[rkward-cvs] SF.net SVN: rkward:[2669] trunk/rkward/rkward/plugins/00saveload/import

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Sep 28 10:41:17 UTC 2009


Revision: 2669
          http://rkward.svn.sourceforge.net/rkward/?rev=2669&view=rev
Author:   tfry
Date:     2009-09-28 10:41:16 +0000 (Mon, 28 Sep 2009)

Log Message:
-----------
updates for Import STATA plugin (Michael ash)

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/00saveload/import/import_stata.php
    trunk/rkward/rkward/plugins/00saveload/import/import_stata.rkh
    trunk/rkward/rkward/plugins/00saveload/import/import_stata.xml

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_stata.php
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_stata.php	2009-09-25 12:07:05 UTC (rev 2668)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_stata.php	2009-09-28 10:41:16 UTC (rev 2669)
@@ -1,22 +1,7 @@
 <?php
 function preprocess () { ?>
 require (foreign)
-<?	if (getRK_val ("do_locale_conversion")) { ?>
-
-# helper function to convert all strings to the current encoding
-iconv.recursive <- function (x, from) {
-	attribs <- attributes (x);
-	if (is.character (x)) {
-		x <- iconv (x, from=from, to="", sub="")
-	} else if (is.list (x)) {
-		x <- lapply (x, function (sub) iconv.recursive (sub, from))
-	}
-	# convert factor levels and all other attributes
-	attributes (x) <- lapply (attribs, function (sub) iconv.recursive (sub, from))
-	x
-}
 <?	}
-}
 
 function calculate () {
 
@@ -54,29 +39,21 @@
 	$object = getRK_val ("saveto");
 ?>
 data <- read.dta ("<? getRK ("file"); ?>"<? echo ($convert_dates_opt); echo ($convert_factors_opt); echo ($missing_type_opt); echo ($convert_underscore_opt); echo ($warn_missing_labels);  ?>)
-<?	if (getRK_val ("do_locale_conversion")) {
-		$from_locale = getRK_val ("encoding");
-		if ($from_locale == "other") {
-			$from_locale = getRK_val ("user_encoding");
-		} ?>
 
-# convert all strings to the current encoding
-data <- iconv.recursive (data, from="<? echo ($from_locale); ?>")
-<?	}
-	if (getRK_val ("convert_var_labels")) { ?>
 
 # set variable labels for use in RKWard
-labels <- attr (data, "variable.labels");
+labels <- attr (data, "var.labels")
 if (!is.null (labels)) {
-	for (i in 1:length (labels)) {
-		col <- make.names (names (labels[i]))
-		if (!is.null (col)) {
-			rk.set.label (data[[col]], labels[i])
-		}
-	}
+        for (i in 1:length (labels)) {
+                col <- make.names (attr (data, "names")[i] )
+                if (!is.null (col)) {
+                        rk.set.label (data[[col]], labels[i])
+                }
+        }
 }
-<?	} ?>
 
+
+
 <? echo ($object); ?> <<- data		# assign to globalenv()
 <?
 	if (getRK_val ("doedit") ) { ?>

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_stata.rkh
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_stata.rkh	2009-09-25 12:07:05 UTC (rev 2668)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_stata.rkh	2009-09-28 10:41:16 UTC (rev 2669)
@@ -5,7 +5,7 @@
 	</summary>
 
 	<usage>
-Choose the STATA data file to import. Usually those files have the ending '*.dta. An R object containing the STATA data will be created. This can either be a data.frame, or a list. Several options deal with handling labels and character encoding. See <link href="rkward://rhelp/read.dta" />. Other STATA files than data files (i. e.:*.log, *.smcl, *.do, *.ado) are not supported. 
+Choose the STATA data file to import. Usually those files have the ending '*.dta. An R object containing the STATA data will be created. This can either be a data.frame, or a list. Several options deal with handling labels and character encoding. See <link href="rkward://rhelp/read.dta" />. STATA files other than data files (i. e.:*.log, *.smcl, *.do, *.ado) are not supported. 
 	</usage>
 
 	<settings>
@@ -13,23 +13,17 @@
 		<setting id="file">The filename of the file to import</setting>
 		<setting id="saveto">The name of an R object to store the imported data in. If you chose an existing symbol name, you will be prompted, whether to overwrite this object.</setting>
 		<setting id="doedit">Whether the object should be opened for editing after it was imported. Currently, this is only possible, if the object is saved as a data.frame (see next option).</setting>
-		<setting id="data_frame">Whether to save the data as a data.frame. The alternative is saving as a list (useful, if the columns in your STATA data have different lengths)</setting>
 
-		<setting id="convert_var_labels">RKWard can display STATA like variable labels. Check this option, if you would like to convert the STATA variable labels to RKWard format. If you leave the option unchecked, the STATA variable labels will still be available as an attribute "variable.labels" (see <link href="rkward://rhelp/read.dta" />)</setting>
-		<setting id="use_labels">Should STATA variables with value labels be converted to R factors with those levels?</setting>
-		<setting id="labels_limit">Maximum number of factor levels to use (see <link href="rkward://rhelp/read.dta" />)</setting>
-		<setting id="trim_labels">Trim trailing white space from labels?</setting>
-
-		<caption id="tab_encoding"/>
-		<setting id="do_locale_conversion">If special character (e.g. umlauts) do not show up correctly, the STATA file probably uses a different locale than your R session. In this case, check this option, and specify the correct character encoding below.</setting>
-		<setting id="encoding">Select character encoding to convert from. The option above needs to be checked, for this to be enabled.</setting>
-		<setting id="user_encoding">If none of the encodings above matches, you can specify an encoding here. Note that the available encodings may differ from platform to platform. See <link href="rkward://rhelp/iconvlist" /> for a list of available encodings.</setting>
+		<setting id="convert_dates">Convert Stata dates to R 'Date' class (see <link href="rkward://rhelp/read.dta" />)</setting>
+		<setting id="convert_factors">Use STATA value labels to create factors </setting>
+		<setting id="missing_type"> For version 8 or later, store information about different types of missing data</setting>
+		<setting id="convert_underscore">Convert '_' in Stata variable names to '.' in R names </setting>
+		<setting id="warn_missing_labels">Warn if a variable is specified with value labels and those value labels are not present in the file</setting>
 	</settings>
 	<related>
 		<ul>
 			<li><link href="rkward://component/import_csv"/></li>
 			<li><link href="rkward://rhelp/read.dta"/></li>
-			<li><link href="rkward://rhelp/iconv"/></li>
 		</ul>
 	</related>
 </document>

Modified: trunk/rkward/rkward/plugins/00saveload/import/import_stata.xml
===================================================================
--- trunk/rkward/rkward/plugins/00saveload/import/import_stata.xml	2009-09-25 12:07:05 UTC (rev 2668)
+++ trunk/rkward/rkward/plugins/00saveload/import/import_stata.xml	2009-09-28 10:41:16 UTC (rev 2669)
@@ -5,17 +5,6 @@
 	<logic>
 		<external id="filename"/>
 		<connect governor="filename" client="file.selection"/>
-		
-		<connect governor="data_frame.state" client="doedit.enabled" />
-		
-		<connect governor="use_labels.state" client="labels_limit.enabled"/>
-		<connect governor="use_labels.state" client="trim_labels.enabled"/>
-		
-		<connect governor="do_locale_conversion.state" client="encoding.enabled" />
-		<convert id="other_encoding" mode="equals" standard="other" sources="encoding.string" />
-		<convert id="other_encoding2" mode="and" sources="other_encoding;do_locale_conversion.state" />
-		<connect governor="other_encoding2" client="user_encoding.enabled" />
-		<connect governor="other_encoding2" client="user_encoding.required" />
 	</logic>
 	<dialog label="Import STATA file">
 		<tabbook>
@@ -35,31 +24,6 @@
 					<checkbox id="warn_missing_labels" checked="true" label="Warn if a variable is specified with value labels and those value labels are not present in the file." value="1" value_unchecked="0"/>
 				</frame>
 			</tab>
-			<tab id="tab_encoding" label="Encoding">
-				<checkbox id="do_locale_conversion" checked="false" label="Convert string encoding" value="1" value_unchecked="0"/>
-				<dropdown id="encoding" label="Convert from:">
-					<option value="latin1" label="Latin 1" checked="true"/>
-					<option value="UTF-8" label="UTF-8"/>
-					<option value="ISO8859-1" label="ISO8859-1 Latin-1 Western European"/>
-					<option value="ISO8859-2" label="ISO8859-2 Latin-2 Central European"/>
-					<option value="ISO8859-3" label="ISO8859-3 Latin-3 South European"/>
-					<option value="ISO8859-4" label="ISO8859-4 Latin-4 North European"/>
-					<option value="ISO8859-5" label="ISO8859-5 Latin/Cyrillic"/>
-					<option value="ISO8859-6" label="ISO8859-6 Latin/Arabic"/>
-					<option value="ISO8859-7" label="ISO8859-7 Latin/Greek"/>
-					<option value="MS-GREEK" label="MS-GREEK"/>
-					<option value="ISO8859-8" label="ISO8859-8 Latin/Hebrew"/>
-					<option value="ISO8859-9" label="ISO8859-9 Latin-5 Turkish"/>
-					<option value="ISO8859-10" label="ISO8859-10 Latin-6 Nordic"/>
-					<option value="ISO8859-11" label="ISO8859-11 Latin/Thai"/>
-					<option value="ISO8859-13" label="ISO8859-13 Latin-7 Baltic Rim"/>
-					<option value="ISO8859-14" label="ISO8859-14 Latin-8 Celtic"/>
-					<option value="ISO8859-15" label="ISO8859-15 Latin-9 Western Europen (EUR)"/>
-					<option value="ISO8859-16" label="ISO8859-16 Latin-10 South-Eastern European"/>
-					<option value="other" label="Other (specify below)"/>
-				</dropdown>
-				<input id="user_encoding" label="Other encoding" />
-			</tab>
 		</tabbook>
 	</dialog>
 </document>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list