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

m-eik at users.sf.net m-eik at users.sf.net
Fri Feb 22 16:14:54 UTC 2013


Revision: 4553
          http://sourceforge.net/p/rkward/code/4553
Author:   m-eik
Date:     2013-02-22 16:14:53 +0000 (Fri, 22 Feb 2013)
Log Message:
-----------
rkwarddev: finding the best way of dealing with optionsets still gives me a headache...

Modified Paths:
--------------
    trunk/rkward/packages/rkwarddev/DESCRIPTION
    trunk/rkward/packages/rkwarddev/NAMESPACE
    trunk/rkward/packages/rkwarddev/R/rk-internal.R
    trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
    trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd

Added Paths:
-----------
    trunk/rkward/packages/rkwarddev/R/id.os.R
    trunk/rkward/packages/rkwarddev/man/id.os.Rd

Modified: trunk/rkward/packages/rkwarddev/DESCRIPTION
===================================================================
--- trunk/rkward/packages/rkwarddev/DESCRIPTION	2013-02-22 16:07:50 UTC (rev 4552)
+++ trunk/rkward/packages/rkwarddev/DESCRIPTION	2013-02-22 16:14:53 UTC (rev 4553)
@@ -15,9 +15,10 @@
 Authors at R: c(person(given="Meik", family="Michalke",
     email="meik.michalke at hhu.de", role=c("aut", "cre")))
 Version: 0.06-2
-Date: 2013-02-21
+Date: 2013-02-22
 Collate:
     'echo.R'
+    'id.os.R'
     'id.R'
     'rk.JS.ite-class.R'
     'ite.R'

Modified: trunk/rkward/packages/rkwarddev/NAMESPACE
===================================================================
--- trunk/rkward/packages/rkwarddev/NAMESPACE	2013-02-22 16:07:50 UTC (rev 4552)
+++ trunk/rkward/packages/rkwarddev/NAMESPACE	2013-02-22 16:14:53 UTC (rev 4553)
@@ -1,13 +1,41 @@
+exportClasses(rk.JS.arr)
+exportClasses(rk.JS.ite)
+exportClasses(rk.JS.opt)
+exportClasses(rk.JS.var)
+exportClasses(rk.plot.opts)
+exportClasses(rk.plug.comp)
 export(echo)
 export(id)
+export(id.os)
 export(ite)
+exportMethods(show)
 export(qp)
+export(rk.build.plugin)
+export(rk.comment)
 export(rk.JS.array)
 export(rk.JS.doc)
 export(rk.JS.options)
 export(rk.JS.saveobj)
 export(rk.JS.scan)
 export(rk.JS.vars)
+export(rk.paste.JS)
+export(rk.paste.JS.graph)
+export(rk.plotOptions)
+export(rk.plugin.component)
+export(rk.plugin.skeleton)
+export(rk.rkh.caption)
+export(rk.rkh.doc)
+export(rk.rkh.link)
+export(rk.rkh.related)
+export(rk.rkh.scan)
+export(rk.rkh.section)
+export(rk.rkh.setting)
+export(rk.rkh.settings)
+export(rk.rkh.summary)
+export(rk.rkh.technical)
+export(rk.rkh.title)
+export(rk.rkh.usage)
+export(rk.testsuite.doc)
 export(rk.XML.about)
 export(rk.XML.attribute)
 export(rk.XML.browser)
@@ -61,32 +89,5 @@
 export(rk.XML.varselector)
 export(rk.XML.varslot)
 export(rk.XML.wizard)
-export(rk.build.plugin)
-export(rk.comment)
-export(rk.paste.JS)
-export(rk.paste.JS.graph)
-export(rk.plotOptions)
-export(rk.plugin.component)
-export(rk.plugin.skeleton)
-export(rk.rkh.caption)
-export(rk.rkh.doc)
-export(rk.rkh.link)
-export(rk.rkh.related)
-export(rk.rkh.scan)
-export(rk.rkh.section)
-export(rk.rkh.setting)
-export(rk.rkh.settings)
-export(rk.rkh.summary)
-export(rk.rkh.technical)
-export(rk.rkh.title)
-export(rk.rkh.usage)
-export(rk.testsuite.doc)
 export(tf)
-exportClasses(rk.JS.arr)
-exportClasses(rk.JS.ite)
-exportClasses(rk.JS.opt)
-exportClasses(rk.JS.var)
-exportClasses(rk.plot.opts)
-exportClasses(rk.plug.comp)
-exportMethods(show)
 import(methods)

Added: trunk/rkward/packages/rkwarddev/R/id.os.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/id.os.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/id.os.R	2013-02-22 16:14:53 UTC (rev 4553)
@@ -0,0 +1,56 @@
+#' Create JavaScript variables from optionsets
+#' 
+#' Scans an \code{<optionset>} node and returns the relevant variable or ID names of each
+#' \code{<optioncolumn>} included.
+#'
+#' This function can be of assistance when dealing with \code{<optionset>} nodes, because what you
+#' need in the JavaScript part of your plugin is the correct variable name of its columns.
+#'
+#' @param optionset An object of class \code{XiMpLe.node} containing a full \code{<optionset>}.
+#' @param js Logical, if \code{TRUE} valid JavaScript varaible names will be returned, otherwise
+#'		the XML ID names, respectively.
+#' @param add.abbrev Logical, if \code{TRUE} the JavaScript variables will all have a prefix with an
+#'		three letter abbreviation of the XML tag type to improve the readability of the code. But it's
+#'		probably better to add this in the XML code in the first place.
+#' @return A character vector. For each \code{<optioncolumn>} in the set, this vector will contain
+#'		either its variable name or XML ID, depending on the \code{js} switch.
+#' @seealso
+#'		\code{\link[rkwarddev:rk.XML.optioncolumn]{rk.XML.optioncolumn}},
+#'		\code{\link[rkwarddev:rk.XML.optiondisplay]{rk.XML.optiondisplay}},
+#'		and the \href{help:rkwardplugins}{Introduction to Writing Plugins for RKWard}
+#' @export
+
+# this is a quick hack which might become obsolete again, if i find a good way of limiting
+# the JS variables to the column ID.
+
+id.os <- function(optionset, js=TRUE, add.abbrev=FALSE){
+
+	if(!is.XiMpLe.node(optionset) || !identical(XMLName(optionset), "optionset")){
+		stop(simpleError("id.os() can only process <optionset> nodes in XiMpLe object form!"))
+	} else {}
+
+	# getting the relevant IDs out of optionsets is a little tricky
+	# this function will probe for sets and return single tags
+	single.tags <- check.optionset.tags(XML.obj=optionset, drop=c("comments","cdata", "declarations", "doctype"))
+
+	JS.id <- get.IDs(single.tags=single.tags, relevant.tags="optioncolumn", add.abbrev=add.abbrev, tag.names=TRUE)
+
+	if("id" %in% colnames(JS.id)){
+		if(isTRUE(js)){
+			JS.lines <- unlist(sapply(1:nrow(JS.id), function(this.id){
+					return(rk.paste.JS(get.JS.vars(
+						JS.var=JS.id[this.id,"abbrev"],
+						XML.var=JS.id[this.id,"id"],
+						tag.name=JS.id[this.id,"tag"],
+						names.only=TRUE), level=1, indent.by=""))
+				}, USE.NAMES=FALSE))
+		} else {
+			JS.lines <- JS.id[,"id"]
+			names(JS.lines) <- NULL
+		}
+	} else {
+		JS.lines <- NULL
+	}
+
+	return(JS.lines)
+}

Modified: trunk/rkward/packages/rkwarddev/R/rk-internal.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk-internal.R	2013-02-22 16:07:50 UTC (rev 4552)
+++ trunk/rkward/packages/rkwarddev/R/rk-internal.R	2013-02-22 16:14:53 UTC (rev 4553)
@@ -100,9 +100,11 @@
 		single.tags <- trim(unlist(strsplit(pasteXMLTree(XML.obj, shine=1, indent.by=""), split="\n")))
 	} else if(is.XiMpLe.node(XML.obj)){
 		single.tags <- trim(unlist(strsplit(pasteXML(XML.obj, shine=1, indent.by=""), split="\n")))
-	} else {
+	} else if(!is.null(XML.obj)){
 		xml.raw <- paste(readLines(XML.obj), collapse=" ")
 		single.tags <- XiMpLe:::XML.single.tags(xml.raw, drop=drop)
+	} else {
+		return(NULL)
 	}
 	names(single.tags) <- NULL
 
@@ -186,9 +188,11 @@
 } ## end function get.IDs()
 
 ## function check.optionset.tags()
-# XML.obj may be a character string (file name) or XiMpLe object
-# this functions will check if <optionset> nodes are present
-# and return a possibly corrected result of get.single.tags()
+# XML.obj may be a character string (file name) or XiMpLe object.
+# this function will check if <optionset> nodes are present
+# and return a possibly corrected result of get.single.tags(),
+# where "corrected" means: optioncolumns will get their IDs prefixed
+# with the set ID, and the rest of the set is discarded.
 check.optionset.tags <- function(XML.obj, drop=NULL){
 	# if this is not a XiMpLe object, transform the file into one
 	if(!is.XiMpLe.node(XML.obj) && !is.XiMpLe.doc(XML.obj)){

Modified: trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R	2013-02-22 16:07:50 UTC (rev 4552)
+++ trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R	2013-02-22 16:14:53 UTC (rev 4553)
@@ -4,7 +4,7 @@
 #' Package: \tab rkwarddev\cr
 #' Type: \tab Package\cr
 #' Version: \tab 0.06-2\cr
-#' Date: \tab 2013-02-21\cr
+#' Date: \tab 2013-02-22\cr
 #' Depends: \tab R (>= 2.9.0),methods,XiMpLe (>= 0.03-18),rkward (>= 0.5.6)\cr
 #' Enhances: \tab rkward\cr
 #' Encoding: \tab UTF-8\cr

Added: trunk/rkward/packages/rkwarddev/man/id.os.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/id.os.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/id.os.Rd	2013-02-22 16:14:53 UTC (rev 4553)
@@ -0,0 +1,43 @@
+\name{id.os}
+\alias{id.os}
+\title{Create JavaScript variables from optionsets}
+\usage{
+  id.os(optionset, js = TRUE, add.abbrev = FALSE)
+}
+\arguments{
+  \item{optionset}{An object of class \code{XiMpLe.node}
+  containing a full \code{<optionset>}.}
+
+  \item{js}{Logical, if \code{TRUE} valid JavaScript
+  varaible names will be returned, otherwise the XML ID
+  names, respectively.}
+
+  \item{add.abbrev}{Logical, if \code{TRUE} the JavaScript
+  variables will all have a prefix with an three letter
+  abbreviation of the XML tag type to improve the
+  readability of the code. But it's probably better to add
+  this in the XML code in the first place.}
+}
+\value{
+  A character vector. For each \code{<optioncolumn>} in the
+  set, this vector will contain either its variable name or
+  XML ID, depending on the \code{js} switch.
+}
+\description{
+  Scans an \code{<optionset>} node and returns the relevant
+  variable or ID names of each \code{<optioncolumn>}
+  included.
+}
+\details{
+  This function can be of assistance when dealing with
+  \code{<optionset>} nodes, because what you need in the
+  JavaScript part of your plugin is the correct variable
+  name of its columns.
+}
+\seealso{
+  \code{\link[rkwarddev:rk.XML.optioncolumn]{rk.XML.optioncolumn}},
+  \code{\link[rkwarddev:rk.XML.optiondisplay]{rk.XML.optiondisplay}},
+  and the \href{help:rkwardplugins}{Introduction to Writing
+  Plugins for RKWard}
+}
+

Modified: trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd	2013-02-22 16:07:50 UTC (rev 4552)
+++ trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd	2013-02-22 16:14:53 UTC (rev 4553)
@@ -9,7 +9,7 @@
 \details{
   \tabular{ll}{ Package: \tab rkwarddev\cr Type: \tab
   Package\cr Version: \tab 0.06-2\cr Date: \tab
-  2013-02-21\cr Depends: \tab R (>= 2.9.0),methods,XiMpLe
+  2013-02-22\cr Depends: \tab R (>= 2.9.0),methods,XiMpLe
   (>= 0.03-18),rkward (>= 0.5.6)\cr Enhances: \tab
   rkward\cr Encoding: \tab UTF-8\cr License: \tab GPL (>=
   3)\cr LazyLoad: \tab yes\cr URL: \tab





More information about the rkward-tracker mailing list