[rkward-cvs] SF.net SVN: rkward:[4128] trunk/rkward/packages/rkwarddev

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Wed Dec 14 22:18:52 UTC 2011


Revision: 4128
          http://rkward.svn.sourceforge.net/rkward/?rev=4128&view=rev
Author:   m-eik
Date:     2011-12-14 22:18:51 +0000 (Wed, 14 Dec 2011)
Log Message:
-----------
rkwarddev: added support for global JS variables

Modified Paths:
--------------
    trunk/rkward/packages/rkwarddev/ChangeLog
    trunk/rkward/packages/rkwarddev/R/rk-internal.R
    trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R
    trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R
    trunk/rkward/packages/rkwarddev/R/rk.plugin.skeleton.R
    trunk/rkward/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf
    trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd
    trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd
    trunk/rkward/packages/rkwarddev/man/rk.plugin.skeleton.Rd

Modified: trunk/rkward/packages/rkwarddev/ChangeLog
===================================================================
--- trunk/rkward/packages/rkwarddev/ChangeLog	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/ChangeLog	2011-12-14 22:18:51 UTC (rev 4128)
@@ -3,6 +3,9 @@
 ## 0.05-0 (2011-12-14)
   - "result.header" now doesn't add quotes by itself in rk.JS.doc(), so you can have R objects pasted.
     previous scripts need to be adapted accordingly! the headers can also be deactivated by setting to FALSE or ""
+  - fixed show method for objects of class rk.JS.var with more than one variable object
+  - added support for global variables to rk.JS.doc() and rk.plugin.component(), and therefore also rk.plugin.skeleton()
+  - "variables" and "globals" in rk.JS.doc() can now also be given as objects of class rk.JS.var
   - worked on the vignette
 
 ## 0.04-13 (2011-12-12)

Modified: trunk/rkward/packages/rkwarddev/R/rk-internal.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk-internal.R	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/R/rk-internal.R	2011-12-14 22:18:51 UTC (rev 4128)
@@ -714,6 +714,9 @@
 					default=default,
 					join=join,
 					names.only=names.only)}))
+	if(!isTRUE(names.only) & !is.null(results)){
+		results <- paste(results, collapse="\n")
+	}
 	if(!isTRUE(names.only)){
 		results <- paste(results, collapse="")
 	} else {}
@@ -749,7 +752,7 @@
 			if(isTRUE(names.only)){
 				results <- c(results, camelCode(c(JS.prefix, JS.var)))
 			} else {
-				results <- paste(results, main.indent, "var ", camelCode(c(JS.prefix, JS.var)), " = getValue(\"", XML.var, "\")", join.code, ";", sep="")
+				results <- paste(main.indent, "var ", camelCode(c(JS.prefix, JS.var)), " = getValue(\"", XML.var, "\")", join.code, ";", sep="")
 			}
 		} else {}
 		if(length(modifiers) > 0){
@@ -765,10 +768,10 @@
 							" = getValue(\"", XML.var, ".", this.modif, "\")", join.code, ";", sep=""))
 					}
 				})
-			if(!identical(results, "")){
+			if(identical(results, "")){
+				results <- modif.results
+			} else {
 				results <- c(results, modif.results)
-			} else {
-				results <- modif.results
 			}
 		}
 	} else {}

Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.doc.R	2011-12-14 22:18:51 UTC (rev 4128)
@@ -3,8 +3,11 @@
 #' @note The JavaScript
 #'
 #' @param require A character vector with names of R packages that the dialog depends on.
-#' @param variables A character string to be included to read in all needed variables from the dialog.
-#'		Refer to \code{\link{rk.JS.scan}} for a function to create this from an existing plugin XML file. 
+#' @param variables Either a character string to be included to read in all needed variables from the dialog (see \code{\link{rk.JS.scan}}),
+#'		or an object of class \code{rk.JS.var} which will be coerced into character. These variables will be defined in
+#'		the \code{calculate()} and/or \code{doPrintout()} functions.
+#' @param globals Like \code{variables}, but these variables will be defined globally. If \code{variables} is set as well,
+#'		the function tries to remove duplicate definitions.
 #' @param results.header A character string to headline the printed results. Include escapes quotes (\\") if needed.
 #'		Set to \code{FALSE} or \code{""} if you need more control and want to define the header section in \code{printout}.
 #' @param preprocess A character string to be included in the \code{preprocess()} function. This string will be
@@ -32,11 +35,40 @@
 #'		and the \href{help:rkwardplugins}{Introduction to Writing Plugins for RKWard}
 #' @export
 
-rk.JS.doc <- function(require=c(), variables=NULL, results.header=NULL,
+rk.JS.doc <- function(require=c(), variables=NULL, globals=NULL, results.header=NULL,
 	preprocess=NULL, calculate=NULL, printout=NULL, doPrintout=NULL, load.silencer=NULL, gen.info=TRUE, indent.by="\t"){
 
+	# some data transformation
+	if(inherits(variables, "rk.JS.var")){
+		variables <- rk.paste.JS(variables)
+	} else {}
+	if(inherits(globals, "rk.JS.var")){
+		globals <- rk.paste.JS(globals, level=1)
+	} else {}
+
 	js.gen.info <- ifelse(isTRUE(gen.info), rk.paste.JS(generator.info, level=1), "")
 
+	if(!is.null(globals)){
+		js.globals <- paste(
+			"// define variables globally\n",
+			paste(globals, collapse=""), sep="")
+		if(!is.null(variables)){
+			# remove globals from variables, if duplicate
+			# we'll split them by semicolon
+			split.globs <- unlist(strsplit(rk.paste.JS(globals), ";"))
+			split.vars <- unlist(strsplit(rk.paste.JS(variables), ";"))
+			# for better comparison, remove all spaces
+			stripped.globs <- gsub("[[:space:]]", "", split.globs)
+			stripped.vars <- gsub("[[:space:]]", "", split.vars)
+			# leave only variables *not* found in globals
+			ok.vars <- split.vars[!stripped.vars %in% stripped.globs]
+			# finally, glue back the semicolon and make one string again
+			variables <- gsub("^\n*", "", paste(paste(ok.vars, ";", sep=""), collapse=""))
+		} else {}
+	} else {
+		js.globals <- NULL
+	}
+
 	js.require <- unlist(sapply(require, function(this.req){
 			if(is.null(load.silencer)){
 				req.result <- rk.paste.JS(echo(id("require(", this.req, ")\n")), level=2, indent.by=indent.by)
@@ -116,7 +148,7 @@
 				sep="")
 	}
 
-	JS.doc <- paste(js.gen.info, js.preprocess, js.calculate, js.printout, js.doPrintout, sep="\n\n")
+	JS.doc <- paste(js.gen.info, js.globals, js.preprocess, js.calculate, js.printout, js.doPrintout, sep="\n\n")
 
 	return(JS.doc)
 }

Modified: trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R	2011-12-14 22:18:51 UTC (rev 4128)
@@ -9,8 +9,8 @@
 #'		If not set, their default values are used. See \code{\link[rkwarddev:rk.XML.plugin]{rk.XML.plugin}} for details.
 #' @param js A named list of options to be forwarded to \code{\link[rkwarddev:rk.JS.doc]{rk.JS.doc}}, to generate the JavaScript file.
 #'		Not all options are supported because some don't make sense in this context. Valid options are:
-#'		\code{"require"}, \code{"results.header"}, \code{"variables"}, \code{"preprocess"}, \code{"calculate"}, \code{"printout"}, \code{"doPrintout"}
-#'		and \code{"load.silencer"}.
+#'		\code{"require"}, \code{"results.header"}, \code{"variables"}, \code{"globals"}, \code{"preprocess"}, \code{"calculate"}, \code{"printout"},
+#'		\code{"doPrintout"} and \code{"load.silencer"}.
 #'		If not set, their default values are used. See \code{\link[rkwarddev:rk.JS.doc]{rk.JS.doc}} for details.
 #' @param rkh A named list of options to be forwarded to \code{\link[rkwarddev:rk.rkh.doc]{rk.rkh.doc}}, to generate the help file.
 #'		Not all options are supported because some don't make sense in this context. Valid options are:
@@ -132,7 +132,7 @@
 	## create plugin.js
 	if("js" %in% create & length(js) > 0){
 		got.JS.options <- names(js)
-		for (this.opt in c("require", "variables", "preprocess", "calculate", "printout", "doPrintout", "load.silencer")){
+		for (this.opt in c("require", "globals", "variables", "preprocess", "calculate", "printout", "doPrintout", "load.silencer")){
 			if(!this.opt %in% got.JS.options) {
 				js[[this.opt]] <- eval(formals(rk.JS.doc)[[this.opt]])
 			} else {}
@@ -158,6 +158,7 @@
 		JS.code <- rk.JS.doc(
 			require=js[["require"]],
 			variables=js[["variables"]],
+			globals=js[["globals"]],
 			results.header=js[["results.header"]],
 			preprocess=js[["preprocess"]],
 			calculate=js[["calculate"]],

Modified: trunk/rkward/packages/rkwarddev/R/rk.plugin.skeleton.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.plugin.skeleton.R	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/R/rk.plugin.skeleton.R	2011-12-14 22:18:51 UTC (rev 4128)
@@ -27,8 +27,8 @@
 #'		If not set, their default values are used. See \code{\link[rkwarddev:rk.XML.plugin]{rk.XML.plugin}} for details.
 #' @param js A named list of options to be forwarded to \code{\link[rkwarddev:rk.JS.doc]{rk.JS.doc}}, to generate the JavaScript file.
 #'		Not all options are supported because some don't make sense in this context. Valid options are:
-#'		\code{"require"}, \code{"results.header"}, \code{"variables"}, \code{"preprocess"}, \code{"calculate"}, \code{"printout"}, \code{"doPrintout"}
-#'		and \code{"load.silencer"}.
+#'		\code{"require"}, \code{"results.header"}, \code{"variables"}, \code{"globals"}, \code{"preprocess"}, \code{"calculate"}, \code{"printout"},
+#'		\code{"doPrintout"} and \code{"load.silencer"}.
 #'		If not set, their default values are used. See \code{\link[rkwarddev:rk.JS.doc]{rk.JS.doc}} for details.
 #' @param pluginmap A named list of options to be forwarded to \code{\link[rkwarddev:rk.XML.pluginmap]{rk.XML.pluginmap}}, to generate the pluginmap file.
 #'		Not all options are supported because some don't make sense in this context. Valid options are:

Modified: trunk/rkward/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf
===================================================================
(Binary files differ)

Modified: trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/man/rk.JS.doc.Rd	2011-12-14 22:18:51 UTC (rev 4128)
@@ -3,20 +3,27 @@
 \title{Create JavaScript outline from RKWard plugin XML}
 \usage{
   rk.JS.doc(require = c(), variables = NULL,
-    results.header = NULL, preprocess = NULL,
-    calculate = NULL, printout = NULL, doPrintout = NULL,
-    load.silencer = NULL, gen.info = TRUE,
-    indent.by = "\t")
+    globals = NULL, results.header = NULL,
+    preprocess = NULL, calculate = NULL, printout = NULL,
+    doPrintout = NULL, load.silencer = NULL,
+    gen.info = TRUE, indent.by = "\t")
 }
 \arguments{
   \item{require}{A character vector with names of R
   packages that the dialog depends on.}
 
-  \item{variables}{A character string to be included to
-  read in all needed variables from the dialog.  Refer to
-  \code{\link{rk.JS.scan}} for a function to create this
-  from an existing plugin XML file.}
+  \item{variables}{Either a character string to be included
+  to read in all needed variables from the dialog (see
+  \code{\link{rk.JS.scan}}), or an object of class
+  \code{rk.JS.var} which will be coerced into character.
+  These variables will be defined in the \code{calculate()}
+  and/or \code{doPrintout()} functions.}
 
+  \item{globals}{Like \code{variables}, but these variables
+  will be defined globally. If \code{variables} is set as
+  well, the function tries to remove duplicate
+  definitions.}
+
   \item{results.header}{A character string to headline the
   printed results. Include escapes quotes (\\") if needed.
   Set to \code{FALSE} or \code{""} if you need more control

Modified: trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd	2011-12-14 22:18:51 UTC (rev 4128)
@@ -34,10 +34,11 @@
   the JavaScript file.  Not all options are supported
   because some don't make sense in this context. Valid
   options are: \code{"require"}, \code{"results.header"},
-  \code{"variables"}, \code{"preprocess"},
-  \code{"calculate"}, \code{"printout"},
-  \code{"doPrintout"} and \code{"load.silencer"}.  If not
-  set, their default values are used. See
+  \code{"variables"}, \code{"globals"},
+  \code{"preprocess"}, \code{"calculate"},
+  \code{"printout"}, \code{"doPrintout"} and
+  \code{"load.silencer"}.  If not set, their default values
+  are used. See
   \code{\link[rkwarddev:rk.JS.doc]{rk.JS.doc}} for
   details.}
 

Modified: trunk/rkward/packages/rkwarddev/man/rk.plugin.skeleton.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.plugin.skeleton.Rd	2011-12-14 18:54:17 UTC (rev 4127)
+++ trunk/rkward/packages/rkwarddev/man/rk.plugin.skeleton.Rd	2011-12-14 22:18:51 UTC (rev 4128)
@@ -65,10 +65,11 @@
   the JavaScript file.  Not all options are supported
   because some don't make sense in this context. Valid
   options are: \code{"require"}, \code{"results.header"},
-  \code{"variables"}, \code{"preprocess"},
-  \code{"calculate"}, \code{"printout"},
-  \code{"doPrintout"} and \code{"load.silencer"}.  If not
-  set, their default values are used. See
+  \code{"variables"}, \code{"globals"},
+  \code{"preprocess"}, \code{"calculate"},
+  \code{"printout"}, \code{"doPrintout"} and
+  \code{"load.silencer"}.  If not set, their default values
+  are used. See
   \code{\link[rkwarddev:rk.JS.doc]{rk.JS.doc}} for
   details.}
 

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