[rkward] rkward/plugins: Add preview to subset data.frame plugin.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Jan 29 16:58:42 UTC 2016


Git commit 5ccb58470c95d7f5ed44a3a5fb0104d02e1209aa by Thomas Friedrichsmeier.
Committed on 29/01/2016 at 16:58.
Pushed by tfry into branch 'master'.

Add preview to subset data.frame plugin.

M  +23   -12   rkward/plugins/data/subset_dataframe.js
M  +4    -1    rkward/plugins/data/subset_dataframe.rkh
M  +39   -36   rkward/plugins/data/subset_dataframe.xml
M  +18   -10   rkward/plugins/rkwarddev_scripts/subset_dataframe.R

http://commits.kde.org/rkward/5ccb58470c95d7f5ed44a3a5fb0104d02e1209aa

diff --git a/rkward/plugins/data/subset_dataframe.js b/rkward/plugins/data/subset_dataframe.js
index 0926e29..99220d6 100644
--- a/rkward/plugins/data/subset_dataframe.js
+++ b/rkward/plugins/data/subset_dataframe.js
@@ -1,14 +1,20 @@
 // this code was generated using the rkwarddev package.
-//perhaps don't make changes here, but in the rkwarddev script instead!
+// perhaps don't make changes here, but in the rkwarddev script instead!
 
 
 
-function preprocess(){
+function preview(){
+	preprocess(true);
+	calculate(true);
+	printout(true);
+}
+
+function preprocess(is_preview){
 	// add requirements etc. here
 
 }
 
-function calculate(){
+function calculate(is_preview){
 	// the R code to be evaluated
 
 	var data = getString ('var_data');
@@ -59,22 +65,27 @@ function calculate(){
 		}
 	}
 	echo ('\n\t)\n\n');
+	if (is_preview) {
+		echo ('preview_data <- sset.result[1:min(dim(sset.result)[1],500),1:min(dim(sset.result)[2],100),drop=FALSE]\n');
+	}
 
 }
 
-function printout(){
+function printout(is_preview){
 	// printout the results
 
 
 
-	//// save result object
-	// read in saveobject variables
-	var svbSvrsltst = getValue("svb_Svrsltst");
-	var svbSvrsltstActive = getValue("svb_Svrsltst.active");
-	var svbSvrsltstParent = getValue("svb_Svrsltst.parent");
-	// assign object to chosen environment
-	if(svbSvrsltstActive) {
-		echo(".GlobalEnv$" + svbSvrsltst + " <- sset.result\n");
+	if(!is_preview) {
+		//// save result object
+		// read in saveobject variables
+		var svbSvrsltst = getValue("svb_Svrsltst");
+		var svbSvrsltstActive = getValue("svb_Svrsltst.active");
+		var svbSvrsltstParent = getValue("svb_Svrsltst.parent");
+		// assign object to chosen environment
+		if(svbSvrsltstActive) {
+			echo(".GlobalEnv$" + svbSvrsltst + " <- sset.result\n");
+		}	
 	}
 
 }
diff --git a/rkward/plugins/data/subset_dataframe.rkh b/rkward/plugins/data/subset_dataframe.rkh
index 6339a22..3341f9e 100644
--- a/rkward/plugins/data/subset_dataframe.rkh
+++ b/rkward/plugins/data/subset_dataframe.rkh
@@ -1,7 +1,7 @@
 <!DOCTYPE rkhelp >
 <document>
 	<!-- this code was generated using the rkwarddev package.
-			perhaps don't make changes here, but in the rkwarddev script instead! -->
+		perhaps don't make changes here, but in the rkwarddev script instead! -->
 	<title>
 		subset_dataframe
 	</title>
@@ -18,6 +18,9 @@
 		<setting id="var_data">
 			Select the data.frame to subset.
 		</setting>
+		<setting id="preview">
+			Preview the resulting subset. Note that the preview is limited to the first 500 rows and 100 columns, for performance reasons.
+		</setting>
 		<caption id="frm_Fltrrwsb" />
 		<setting id="vrsl_Fltrbyvr">
 			Select a column of the data.frame specifying the condition to filter cases on. Leave empty, if you do not want to filter on a column.
diff --git a/rkward/plugins/data/subset_dataframe.xml b/rkward/plugins/data/subset_dataframe.xml
index b3d7da4..1123881 100644
--- a/rkward/plugins/data/subset_dataframe.xml
+++ b/rkward/plugins/data/subset_dataframe.xml
@@ -1,43 +1,45 @@
 <!DOCTYPE rkplugin >
 <document>
 	<!-- this code was generated using the rkwarddev package.
-			perhaps don't make changes here, but in the rkwarddev script instead! -->
+		perhaps don't make changes here, but in the rkwarddev script instead! -->
 	<code file="subset_dataframe.js" />
 	<help file="subset_dataframe.rkh" />
+	<!-- <dependencies>
+			</dependencies> -->
 	<logic>
 		<script>
 			<![CDATA[ 
 				gui.addChangeCommand("vrsl_Fltrbyvr.available", "dataChanged()");
-							// this function is called whenever the data was changed
-							dataChanged = function(){
-									var enableVarInput = "true";
-									var dataMode = "any";
-									var thisObject = makeRObject(gui.getValue("vrsl_Fltrbyvr.available"));
-									 if(thisObject.classes()){
-										if(thisObject.isDataFactor() || thisObject.isDataCharacter()){
-											dataMode = "char_factor";
-										} else if(thisObject.isDataLogical()){
-											dataMode = "logical";
-											// NOTE: not hiding VarInput to avoid nasty flicker
-											enableVarInput = "false";
-										} else if(thisObject.isDataNumeric()){
-											dataMode="numeric";
-										}
-									} else {}
-									gui.setValue("drp_fltr_fct.visible", dataMode == 'char_factor' ? 'true' : 'false');
-									gui.setValue("drp_fltr_lgc.visible", dataMode == 'logical' ? 'true' : 'false');
-									gui.setValue("drp_fltr_num.visible", dataMode == 'numeric' ? 'true' : 'false');
-									gui.setValue("drp_fltr_all.visible", dataMode == 'any' ? 'true' : 'false');
-									gui.setValue("inp_Vlpstdss.enabled", enableVarInput);
-									gui.setValue("case_filter_data_mode", dataMode);
+					// this function is called whenever the data was changed
+					dataChanged = function(){
+							var enableVarInput = "true";
+							var dataMode = "any";
+							var thisObject = makeRObject(gui.getValue("vrsl_Fltrbyvr.available"));
+							 if(thisObject.classes()){
+								if(thisObject.isDataFactor() || thisObject.isDataCharacter()){
+									dataMode = "char_factor";
+								} else if(thisObject.isDataLogical()){
+									dataMode = "logical";
+									// NOTE: not hiding VarInput to avoid nasty flicker
+									enableVarInput = "false";
+								} else if(thisObject.isDataNumeric()){
+									dataMode="numeric";
 								}
-								dataChanged (); // initialize 
+							} else {}
+							gui.setValue("drp_fltr_fct.visible", dataMode == 'char_factor' ? 'true' : 'false');
+							gui.setValue("drp_fltr_lgc.visible", dataMode == 'logical' ? 'true' : 'false');
+							gui.setValue("drp_fltr_num.visible", dataMode == 'numeric' ? 'true' : 'false');
+							gui.setValue("drp_fltr_all.visible", dataMode == 'any' ? 'true' : 'false');
+							gui.setValue("inp_Vlpstdss.enabled", enableVarInput);
+							gui.setValue("case_filter_data_mode", dataMode);
+						}
+						dataChanged (); // initialize 
 			]]>
 		</script>
-		<connect governor="current_object" client="var_data.available" />
+		<connect governor="current_object.state" client="var_data.available" />
 		<connect governor="var_data.available" client="vrs_Selectdt.root" />
-		<convert id="lgc_vardata" sources="var_data.available" mode="notequals" />
-		<convert id="lgc_vrslFltr" sources="vrsl_Fltrbyvr.available" mode="notequals" />
+		<convert id="lgc_vardata" sources="var_data.available" mode="notequals" standard="" />
+		<convert id="lgc_vrslFltr" sources="vrsl_Fltrbyvr.available" mode="notequals" standard="" />
 		<connect governor="lgc_vardata" client="frm_Onlyssbs.enabled" />
 		<connect governor="lgc_vardata" client="frm_Fltrrwsb.enabled" />
 		<connect governor="lgc_vardata" client="frame_filter_exp.enabled" />
@@ -53,11 +55,11 @@
 			<case standard="range" fixed_value="1" />
 			<default fixed_value="0" />
 		</switch>
-		<connect governor="swt_swtcsflt.state" client="row_cMMIMMIMMI.visible" />
-		<connect governor="row_cMMIMMIMMI.visible.not" client="inp_Vlpstdss.visible" />
+		<connect governor="swt_swtcsflt.state" client="row_clmnMMIMMI.visible" />
+		<connect governor="row_clmnMMIMMI.visible.not" client="inp_Vlpstdss.visible" />
 		<connect governor="lgc_vrslFltr" client="inp_Vlpstdss.required" />
-		<convert id="lgc_inpMnmmr" sources="inp_Mnmmrmpt.text" mode="notequals" />
-		<convert id="lgc_inpMxmmr" sources="inp_Mxmmrmpt.text" mode="notequals" />
+		<convert id="lgc_inpMnmmr" sources="inp_Mnmmrmpt.text" mode="notequals" standard="" />
+		<convert id="lgc_inpMxmmr" sources="inp_Mxmmrmpt.text" mode="notequals" standard="" />
 		<convert id="lgc_lgcnpMxm" sources="lgc_inpMxmmr.not;swt_swtcsflt" mode="and" />
 		<convert id="lgc_lgcnpMnm" sources="lgc_inpMnmmr.not;swt_swtcsflt" mode="and" />
 		<connect governor="lgc_lgcnpMnm" client="inp_Mxmmrmpt.required" />
@@ -70,7 +72,7 @@
 				<varslot id="var_data" label="Data (data.frame)" source="vrs_Selectdt" classes="data.frame" required="true" />
 				<tabbook>
 					<tab label="Filter cases" id="tab_Filtrcss">
-						<column id="clm_fFFFFSKKKT">
+						<column>
 							<frame label="Filter rows by variable" id="frm_Fltrrwsb">
 								<varslot id="vrsl_Fltrbyvr" label="Filter by variable" source="vrs_Selectdt" />
 								<dropdown id="drp_fltr_all" label="Keep cases matching rule">
@@ -97,12 +99,12 @@
 									<option label="is not between" value="!range" />
 								</dropdown>
 								<input label="Value (pasted as-is, use proper quoting!)" id="inp_Vlpstdss" required="true" />
-								<row id="row_cMMIMMIMMI">
-									<column id="clm_inptlblMMI">
+								<row id="row_clmnMMIMMI">
+									<column>
 										<input label="Minimum (or empty)" id="inp_Mnmmrmpt" />
 										<checkbox id="mininc" label="Included (>=)" value="true" />
 									</column>
-									<column id="clm_inptlblMMI">
+									<column>
 										<input label="Maximum (or empty)" id="inp_Mxmmrmpt" />
 										<checkbox id="maxinc" label="Included (<=)" value="true" />
 									</column>
@@ -115,7 +117,7 @@
 						</column>
 					</tab>
 					<tab label="Filter columns" id="tab_Fltrclmn">
-						<column id="clm_frmlbOOSSS">
+						<column>
 							<frame label="Only use a subset of variables" checkable="true" checked="false" id="frm_Onlyssbs">
 								<varslot id="vrsl_Slctdvrb" label="Selected variables" source="vrs_Selectdt" multi="true" />
 							</frame>
@@ -124,6 +126,7 @@
 					</tab>
 				</tabbook>
 				<saveobject label="Save results to workspace" checkable="true" checked="true" initial="sset.result" id="svb_Svrsltst" />
+				<preview mode="data" label="Preview" id="preview" />
 			</column>
 		</row>
 	</dialog>
diff --git a/rkward/plugins/rkwarddev_scripts/subset_dataframe.R b/rkward/plugins/rkwarddev_scripts/subset_dataframe.R
index 8438c0e..4f43b0d 100644
--- a/rkward/plugins/rkwarddev_scripts/subset_dataframe.R
+++ b/rkward/plugins/rkwarddev_scripts/subset_dataframe.R
@@ -17,8 +17,9 @@
 # - split into two plugins (one for rows, one for columns)?
 
 require(rkwarddev)
+rkwarddev.required("0.08-2")
 
-local({
+rk.local({
 # set the output directory to overwrite the actual plugin
 output.dir <- tempdir()
 overwrite <- TRUE
@@ -35,7 +36,7 @@ about.info <- rk.XML.about(
 		person(given="Thomas", family="Friedrichsmeier",
 			email="thomas.friedrichsmeier at kdemail.net", role=c("aut"))),
 	about=list(desc="RKWard GUI to define subsets of data objects",
-		version="0.02-1", url="http://rkward.kde.org")
+		version="0.03-1", url="http://rkward.kde.org")
 )
 
 ############
@@ -90,8 +91,8 @@ sset.filter.min.inc <- rk.XML.checkbox (label="Included (>=)", id.name="mininc")
 sset.filter.max <- rk.XML.input(label="Maximum (or empty)")
 sset.filter.max.inc <- rk.XML.checkbox (label="Included (<=)", id.name="maxinc")	#NOTE: Auto-id bug!
 sset.range.options <- rk.XML.row (
-	rk.XML.col (sset.filter.min, sset.filter.min.inc),
-	rk.XML.col (sset.filter.max, sset.filter.max.inc)
+	rk.XML.col (sset.filter.min, sset.filter.min.inc, id.name=NULL),
+	rk.XML.col (sset.filter.max, sset.filter.max.inc, id.name=NULL)
 )
 
 frame.filter.var <- rk.XML.frame(
@@ -137,6 +138,7 @@ lgc.filter.script <- rk.comment(id("
 		dataChanged (); // initialize", js=FALSE))
 
 save.results.sset <- rk.XML.saveobj("Save results to workspace", initial="sset.result", chk=TRUE)
+sset.preview <- rk.XML.preview (mode="data", label="Preview")
 
 sset.dialog.contents <- rk.XML.row (
 	var.select,
@@ -146,13 +148,14 @@ sset.dialog.contents <- rk.XML.row (
 			"Filter cases"=rk.XML.col(
 				frame.filter.var,
 				frame.filter.expression,
-				rk.XML.stretch()
-			), "Filter columns"=rk.XML.col(
+				rk.XML.stretch(),
+			id.name=NULL), "Filter columns"=rk.XML.col(
 				frame.selected.vars,
-				rk.XML.stretch()
-			))
+				rk.XML.stretch(),
+			id.name=NULL))
 		),
-		save.results.sset
+		save.results.sset,
+		sset.preview
 	)
 )
 
@@ -234,6 +237,9 @@ sset.js.calc <- id("
 		}
 	}
 	echo ('\\n\\t)\\n\\n');
+	if (is_preview) {
+		echo ('preview_data <- sset.result[1:min(dim(sset.result)[1],500),1:min(dim(sset.result)[2],100),drop=FALSE]\\n');
+	}
 ", js=FALSE)
 
 #############
@@ -250,12 +256,14 @@ sset.plugin.dir <<- rk.plugin.skeleton(
   		logic=lgc.sect.sset
 		),
 	js=list(results.header=FALSE,
-		calculate=sset.js.calc),
+		calculate=sset.js.calc,
+		preview=TRUE),
 	rkh=list(
 		summary = rk.rkh.summary ("Select a subset of rows and / or columns of a data.frame"),
 		usage = rk.rkh.usage ("Select the data.frame to subset. Then specify rules to filter by rows / cases, and / or columns. A data.frame containing only the specified subset is saved to your workspace."),
 		settings = rk.rkh.settings (list (
 			rk.rkh.setting (var.data, "Select the data.frame to subset."),
+			rk.rkh.setting (sset.preview, "Preview the resulting subset. Note that the preview is limited to the first 500 rows and 100 columns, for performance reasons."),
 			rk.rkh.caption (frame.filter.var),
 			rk.rkh.setting (filter.var, "Select a column of the data.frame specifying the condition to filter cases on. Leave empty, if you do not want to filter on a column."),
 			rk.rkh.setting (sset.filter.drop, "Select the type of condition. Note that depending on the type of the filter variable, different options are available"),



More information about the rkward-tracker mailing list