[rkward-cvs] SF.net SVN: rkward-code:[4843] trunk/rkward/rkward/plugins/data

tfry at users.sf.net tfry at users.sf.net
Mon Sep 22 15:37:09 UTC 2014


Revision: 4843
          http://sourceforge.net/p/rkward/code/4843
Author:   tfry
Date:     2014-09-22 15:37:09 +0000 (Mon, 22 Sep 2014)
Log Message:
-----------
Handle input NAs in recode_categorical plugin.

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/data/recode_categorical.js
    trunk/rkward/rkward/plugins/data/recode_categorical.xml

Modified: trunk/rkward/rkward/plugins/data/recode_categorical.js
===================================================================
--- trunk/rkward/rkward/plugins/data/recode_categorical.js	2014-09-22 15:35:59 UTC (rev 4842)
+++ trunk/rkward/rkward/plugins/data/recode_categorical.js	2014-09-22 15:37:09 UTC (rev 4843)
@@ -25,14 +25,17 @@
 	}
 
 	// Make replacements
-	var old_values = getList ("set.values");
-	var new_values_types = getList ("set.new_value_types");
-	var new_values_strings = getList ("set.new_value_strings");
+	var old_value_types = getList ("set.old_value_types");
+	var old_value_strings = getList ("set.old_value_strings");
+	var new_value_types = getList ("set.new_value_types");
+	var new_value_strings = getList ("set.new_value_strings");
 
 	var dupes = Array ();
 	var all_old_values = Array ();
-	for (var i = 0; i < old_values.length; ++i) {
-		var old_values_it = old_values[i].split ('\n');
+	for (var i = 0; i < old_value_types.length; ++i) {
+		var old_values_it;
+		if (old_value_types[i] == "na") old_values_it = Array ("NA");
+		else old_values_it = old_value_strings[i].split ('\n');
 
 		// Check for duplicate old values, as the UI does not currently support this!
 		for (var j = 0; j < old_values_it.length; ++j) {
@@ -45,18 +48,19 @@
 
 		var old_index;
 		if (old_values_it.length > 1) {
-			old_index = ' %in% c(' + old_values_it.join (',') + ')';
+			old_index = 'input %in% c(' + old_values_it.join (',') + ')';
 		} else {
-			old_index = ' == ' + old_values_it;
+			if (old_values_it == "NA") old_index = 'is.na (input)';
+			else old_index = 'input == ' + old_values_it;
 		}
 
 		var replacement = 'NA';
-		if (new_values_types[i] != "na") {
-			replacement = new_values_strings[i];
+		if (new_value_types[i] != "na") {
+			replacement = new_value_strings[i];
 			if (quote_new_values) replacement = quote (replacement);
 		}
 
-		echo ('recoded[input' + old_index + '] <- ' + replacement + '\n');
+		echo ('recoded[' + old_index + '] <- ' + replacement + '\n');
 	}
 
 	// Produce warnings (or should it be errors?)

Modified: trunk/rkward/rkward/plugins/data/recode_categorical.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/recode_categorical.xml	2014-09-22 15:35:59 UTC (rev 4842)
+++ trunk/rkward/rkward/plugins/data/recode_categorical.xml	2014-09-22 15:37:09 UTC (rev 4843)
@@ -44,14 +44,27 @@
 				<column>
 					<optionset id="set" min_rows="1">
 						<logic>
+							<convert id="old_value_na" mode="equals" sources="old_value_type.string" standard="na"/>
+							<connect client="levels.enabled" governor="old_value_na.not"/>
+							<connect client="values.enabled" governor="old_value_na.not"/>
+
 							<convert id="new_value_na" mode="equals" sources="new_value.string" standard="na"/>
 							<connect client="new_value_custom.enabled" governor="new_value_na.not"/>
-							<switch condition="new_value.string" id="new_value_string">
-								<case standard="na" fixed_value="_NA_" />
-								<default dynamic_value="new_value_custom.text" />
+
+							<!-- The purpose of these switch-properties is to provide readable labels for NA / value -->
+							<switch condition="old_value_na" id="old_value_string">
+								<true fixed_value="NA" />
+								<false dynamic_value="values.available" />
 							</switch>
+							<switch condition="new_value_na" id="new_value_string">
+								<true standard="na" fixed_value="_NA_" />
+								<false dynamic_value="new_value_custom.text" />
+							</switch>
 						</logic>
-						<optioncolumn id="values" connect="values.available" label="Old value(s)"/>
+						<optioncolumn id="old_values_labelled" connect="old_value_string" label="Old value(s)"/>
+						<optioncolumn id="old_value_types" connect="old_value_type.string"/>
+						<optioncolumn id="old_value_strings" connect="values.available"/>
+
 						<optioncolumn id="new_values_labelled" connect="new_value_string" label="New value(s)"/>
 						<optioncolumn id="new_value_types" connect="new_value.string"/>
 						<optioncolumn id="new_value_strings" connect="new_value_custom.text"/>
@@ -60,41 +73,37 @@
 								<optiondisplay index="true"/>
 								<row>
 									<column>
-										<text type="normal">Old values</text>
-										<!-- TODO Allow selecting NAs in input -->
-										<embed id="levels" component="rkward::level_select"/>
-									</column>
-									<column>
+										<radio id="old_value_type" label="Old values">
+											<option value="na" label="NA"/>
+											<option value="value" label="Select value(s):" checked="true"/>
+										</radio>
 										<row>
-											<valueslot multi="true" min_vars="1" id="values" label="Values to recode" source="levels.selector"/>
-											<column>
-												<radio id="new_value" label="New value">
-													<option value="na" label="NA"/>
-													<option value="custom" label="Value:" checked="true"/>
-												</radio>
-												<input id="new_value_custom" label=""/>
-												<text id="quotation_note" type="normal">(Value will be quoted, automatically)</text>
-												<stretch/>
-											</column>
+											<embed id="levels" component="rkward::level_select"/>
+											<valueslot multi="true" min_vars="1" id="values" label="" source="levels.selector"/>
 										</row>
 									</column>
+									<column>
+										<radio id="new_value" label="New value">
+											<option value="na" label="NA"/>
+											<option value="custom" label="Value:" checked="true"/>
+										</radio>
+										<input id="new_value_custom" label=""/>
+										<text id="quotation_note" type="normal">(Value will be quoted, automatically)</text>
+										<stretch/>
+									</column>
 								</row>
 							</frame>
 						</content>
 					</optionset>
 				</column>
 			</row>
-			<row>
-				<radio id="other" label="Any other values">	<!-- TODO Should this be including original NAs? -->
-					<option value="copy" label="Copy" id="copy_others"/>
-					<option value="na" label="NA"/>
-					<option value="custom" label="Custom value:"/>
-				</radio>
-				<column>
-					<input id="other_custom" label="Value"/>
-					<stretch/>
-				</column>
-			</row>
+			<radio id="other" label="Any other values">	<!-- TODO Should this be including original NAs? -->
+				<option value="copy" label="Copy" id="copy_others"/>
+				<option value="na" label="NA"/>
+				<option value="custom" label="Custom value:"/>
+			</radio>
+			<input id="other_custom" label=""/>
+			<stretch/>
 		</tab>
 	</tabbook></dialog>
 </document>
\ No newline at end of file





More information about the rkward-tracker mailing list