[rkward-cvs] SF.net SVN: rkward:[4479] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Dec 5 15:23:46 UTC 2012


Revision: 4479
          http://rkward.svn.sourceforge.net/rkward/?rev=4479&view=rev
Author:   tfry
Date:     2012-12-05 15:23:45 +0000 (Wed, 05 Dec 2012)
Log Message:
-----------
Make first use of optionset, for fine-tuning of sorting by several columns of a data.frame

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

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2012-12-05 15:16:17 UTC (rev 4478)
+++ trunk/rkward/ChangeLog	2012-12-05 15:23:45 UTC (rev 4479)
@@ -1,3 +1,4 @@
+- Sort plugin gains option to sort data.frames by more than one column at a time, and options for type conversion	TODO: adjust test(s)
 - Add in-application debug message viewer (targetted at (plugin) developers)
 - Add setting to customize initial working directory
 - Windows only: Add UI-checkbox for R's "internet2"-option

Modified: trunk/rkward/rkward/plugins/data/sort.js
===================================================================
--- trunk/rkward/rkward/plugins/data/sort.js	2012-12-05 15:16:17 UTC (rev 4478)
+++ trunk/rkward/rkward/plugins/data/sort.js	2012-12-05 15:23:45 UTC (rev 4479)
@@ -1,13 +1,39 @@
+function makeSortItem (objectname, reversed, mode, conversion_custom) {
+	var obj = objectname;
+	if (mode == 'character') obj = 'as.character (' + obj + ')';
+	else if (mode == 'number') obj = 'as.numeric (' + obj + ')';
+	else if (mode == 'custom') {
+		obj = conversion_custom.replace (/_X_/g, obj);
+	}
+	if (reversed) {
+		if (mode != 'number') obj = '-xtfrm (' + obj + ')';
+		else obj = '-' + obj;
+	}
+	return obj;
+}
+
 function calculate () {
-	var object = getValue ("object");
-	var is_data_frame = getValue ("sortby.enabled.numeric");
+	var object = getString ("object");
+	var is_data_frame = getBoolean ("sortby.enabled");
 
 	var saveto = object;
-	if (getValue ("saveto_select") == "other") saveto = getValue ("saveto");
-	var sortby = getValue ("sortby");
-	if (!is_data_frame) sortby = object;
+	if (getString ("saveto_select") == 'other') saveto = getString ("saveto");
+	var sortby;
+	if (is_data_frame) {
+		sortby = "";
+		var sortbylist = getList ("sortby");
+		var sortbyreverse = getList ("multi_sortby.reverse");
+		var sortbymode = getList ("multi_sortby.conversion");
+		var sortbycustom = getList ("multi_sortby.conversion_custom");
+		for (var i = 0; i < sortbylist.length; ++i) {
+			if (i > 0) sortby = sortby + ', ';
+			sortby = sortby + makeSortItem (sortbylist[i], sortbyreverse[i] != "", sortbymode[i], sortbycustom[i]);
+		}
+	} else {
+		sortby = makeSortItem (object, false, getString ("conversion"), getString ("conversion_custom"));
+	}
 
-	echo (".GlobalEnv$" + saveto + " <- " + object + "[order (" + sortby + getValue ("order") + ")");
-	if (is_data_frame) echo (",");
-	echo ("]\n");
+	echo ('.GlobalEnv$' + saveto + ' <- ' + object + '[order (' + sortby + getString ("order") + ')');
+	if (is_data_frame) echo (',');
+	echo (']\n');
 }

Modified: trunk/rkward/rkward/plugins/data/sort.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/sort.xml	2012-12-05 15:16:17 UTC (rev 4478)
+++ trunk/rkward/rkward/plugins/data/sort.xml	2012-12-05 15:23:45 UTC (rev 4479)
@@ -3,12 +3,21 @@
 	<code file="sort.js"/>
 	<help file="sort.rkh"/>
 	<logic>
-		<set id="vectormode" to="0"/>
 		<connect governor="current_dataframe" client="object.available"/>
 		<convert id="isok" mode="equals" sources="notice.text" standard="" require_true="true"/>
 
 		<convert id="saveto_other_object" mode="equals" sources="saveto_select.string" standard="other"/>
 		<connect governor="saveto_other_object" client="saveto.enabled"/>
+
+		<connect governor="sortby.enabled" client="multi_sortby.visible"/>
+		<connect governor="sortby.enabled.not" client="conversion_specs.visible"/>
+		<connect governor="sortby.available" client="multi_sortby.object"/>
+		<connect governor="sortby.available.shortname" client="multi_sortby.objectshort"/>
+
+		<convert id="custom_conversion" mode="equals" sources="conversion.string" standard="custom"/>
+		<connect governor="custom_conversion" client="conversion_custom.enabled"/>
+		<convert id="custom_conversion_multi" mode="equals" sources="multi_sortby.contents.conversion.string" standard="custom"/>
+		<connect governor="custom_conversion_multi" client="multi_sortby.contents.conversion_custom.enabled"/>
 		<script><![CDATA[
 			// the top-level block is called only once
 			gui.addChangeCommand ("object.available", "objectChanged ()");
@@ -29,26 +38,57 @@
 			}
 			]]></script>
 	</logic>
+
 	<dialog label="Sort data">
-		<row>
-			<varselector id="selector"/>
-			<column>
-				<varslot id="object" source="selector" label="Object to be sorted" required="true"/>
-				<text id="notice" type="warning"></text>
+		<tabbook>
+			<tab label="Basic settings">
+				<row>
+					<varselector id="selector"/>
+					<column>
+						<varslot id="object" source="selector" label="Object to be sorted" required="true"/>
+						<text id="notice" type="warning"></text>
+						<stretch/>
+						<varslot source="selector" id="sortby" label="Sort by" required="true" multi="true" min_vars="1"/>
+					</column>
+				</row>
+				<row>
+					<radio id="saveto_select" label="Save to">
+						<option label="Same object" value="same" checked="true"/>
+						<option label="Another object" value="other"/>
+					</radio>
+					<saveobject id="saveto" label="Object to save to" initial="sorted"/>
+				</row>
 				<stretch/>
-				<varslot source="selector" id="sortby" label="Sort by" required="true"/>
-				<radio id="order" label="Order">
+			</tab>
+			<tab label="Sort order">
+				<radio id="order" label="Sort order">
 					<option label="Ascending" value="" checked="true"/>
 					<option label="Descending" value=", decreasing=TRUE"/>
 				</radio>
-			</column>
-		</row>
-		<row>
-			<radio id="saveto_select" label="Save to">
-				<option label="Same object" value="same" checked="true"/>
-				<option label="Another object" value="other"/>
-			</radio>
-			<saveobject id="saveto" label="Object to save to" initial="sorted"/>
-		</row>
+				<row id="conversion_specs">
+					<dropdown id="conversion" label="Sort mode">
+						<option label="Sort as is" checked="true" value="as is"/>
+						<option label="Sort as character" value="character"/>
+						<option label="Sort as number" value="number"/>
+						<option label="Sort by custom function:" value="custom"/>
+					</dropdown>
+					<input id="conversion_custom" label="Function(_X_) to use for sorting" initial="nchar (as.character (_X_))"/>
+				</row>
+
+				<optionset id="multi_sortby" keycolumn="object">
+					<content>
+						<optiondisplay index="true"/>
+						<checkbox id="reverse" label="Reverse sort order" checked="false" value="Reversed" value_unchecked=""/>
+						<copy id="conversion_specs"/>
+					</content>
+					<optioncolumn id="object" external="true"/>
+					<optioncolumn id="objectshort" external="true" label="Object"/>
+					<optioncolumn id="reverse" label="Order" connect="reverse.state.labeled"/>
+					<optioncolumn id="conversion" label="Sort mode" connect="conversion.string"/>
+					<optioncolumn id="conversion_custom" connect="conversion_custom.text"/>
+				</optionset>
+				<stretch/>
+			</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