[rkward-cvs] SF.net SVN: rkward-code:[4769] trunk/rkward/packages/rkwarddev
m-eik at users.sf.net
m-eik at users.sf.net
Sun Nov 24 23:02:44 UTC 2013
Revision: 4769
http://sourceforge.net/p/rkward/code/4769
Author: m-eik
Date: 2013-11-24 23:02:40 +0000 (Sun, 24 Nov 2013)
Log Message:
-----------
rkwarddev: new function and feature to check for duplicate IDs in generated scripts. no automated fixing possible yet, because this is quite tricky to implement reliably.
also, rk.JS.array() can now be forced to quote values in the generated R code
Modified Paths:
--------------
trunk/rkward/packages/rkwarddev/ChangeLog
trunk/rkward/packages/rkwarddev/DESCRIPTION
trunk/rkward/packages/rkwarddev/R/rk-internal.R
trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R
trunk/rkward/packages/rkwarddev/R/rk.JS.array.R
trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R
trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd
trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd
Added Paths:
-----------
trunk/rkward/packages/rkwarddev/R/rk.uniqueIDs.R
trunk/rkward/packages/rkwarddev/man/rk.uniqueIDs.Rd
Modified: trunk/rkward/packages/rkwarddev/ChangeLog
===================================================================
--- trunk/rkward/packages/rkwarddev/ChangeLog 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/ChangeLog 2013-11-24 23:02:40 UTC (rev 4769)
@@ -1,11 +1,15 @@
ChangeLog for package rkwarddev
-changes in version 0.06-3 (2013-07-05)
+changes in version 0.06-3 (2013-11-25)
fixed:
- fixed outdated example code for rk.plugin.component()
+added:
+ - new function rk.uniqueIDs() checks for duplicate IDs
+ - rk.JS.array() can now be told to quote values
changed:
- rk.plugin.component() and rk.rkh.doc() do now interpret the "hints" argument to prevent the
generation of optional XML nodes.
+ - rk.plugin.component() now automatically calls rk.uniqueIDs() and stops if IDs are not unique
changes in version 0.06-2 (2013-04-04)
changed:
Modified: trunk/rkward/packages/rkwarddev/DESCRIPTION
===================================================================
--- trunk/rkward/packages/rkwarddev/DESCRIPTION 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/DESCRIPTION 2013-11-24 23:02:40 UTC (rev 4769)
@@ -15,7 +15,7 @@
Authors at R: c(person(given="Meik", family="Michalke",
email="meik.michalke at hhu.de", role=c("aut", "cre")))
Version: 0.06-3
-Date: 2013-07-05
+Date: 2013-11-24
Collate:
'echo.R'
'id.R'
@@ -55,6 +55,7 @@
'rk.rkh.title.R'
'rk.rkh.usage.R'
'rk.testsuite.doc.R'
+ 'rk.uniqueIDs.R'
'rkwarddev-desc-internal.R'
'rkwarddev-package.R'
'rk.XML.about.R'
Modified: trunk/rkward/packages/rkwarddev/R/rk-internal.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk-internal.R 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/R/rk-internal.R 2013-11-24 23:02:40 UTC (rev 4769)
@@ -891,6 +891,7 @@
arr.name <- slot(object, "arr.name")
opt.name <- slot(object, "opt.name")
variables <- slot(object, "variables")
+ quote <- slot(object, "quote")
option <- slot(object, "option")
if(is.null(funct)){
funct <- slot(object, "funct")
@@ -902,7 +903,7 @@
funct.start <- paste0(funct, "(")
funct.end <- ")"
}
-
+
JS.array <- paste0(
main.indent, "// define the array ", arr.name, " for values of R option \"", option, "\"\n",
main.indent, "var ", arr.name, " = new Array();\n",
@@ -916,7 +917,10 @@
main.indent, "if(", arr.name, ".length > 0) {\n",
scnd.indent, "var ", opt.name, " = \", ",
ifelse(identical(option, ""), "", paste0(option, "=")),
- funct.start, "\" + ", arr.name, ".join(\", \") + \"",funct.end,"\";\n",
+ ifelse(isTRUE(quote),
+ paste0(funct.start, "\\\"\" + ", arr.name, ".join(\"\\\", \\\"\") + \"\\\"",funct.end,"\";\n"),
+ paste0(funct.start, "\" + ", arr.name, ".join(\", \") + \"",funct.end,"\";\n")
+ ),
main.indent, "} else {\n",
scnd.indent, "var ", opt.name, " = \"\";\n",
main.indent, "}\n")
Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.arr-class.R 2013-11-24 23:02:40 UTC (rev 4769)
@@ -10,6 +10,7 @@
IDs="vector",
variables="vector",
funct="character",
+ quote="logical",
option="character"
),
prototype(
@@ -18,6 +19,7 @@
IDs=c(),
variables=c(),
funct="c",
+ quote=FALSE,
option=character()
)
)
Modified: trunk/rkward/packages/rkwarddev/R/rk.JS.array.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.JS.array.R 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/R/rk.JS.array.R 2013-11-24 23:02:40 UTC (rev 4769)
@@ -11,6 +11,8 @@
#' @param funct Character string, name of the R function to be called to combine the options, e.g. "list" for \code{list()},
#' or "c" for \code{c()}.
#' @param var.prefix A character string. sets a global string to be used as a prefix for the JS variable names.
+#' @param quote Logical, if \code{TRUE}, the values will be quoted in the resulting R code (might be neccessary
+#' for character values).
#' @return An object of class \code{rk.JS.arr}.
#' @export
#' @seealso \code{\link[rkwarddev:rk.paste.JS]{rk.paste.JS}},
@@ -27,7 +29,7 @@
#' # combine them into one list of options via JavaScript
#' rk.JS.array("run.tests", variables=list(checkA, checkB, checkC), funct="list")
-rk.JS.array <- function(option, variables=list(), funct="c", var.prefix=NULL){
+rk.JS.array <- function(option, variables=list(), funct="c", var.prefix=NULL, quote=FALSE){
arr.name <- camelCode(c("arr", option))
opt.name <- camelCode(c("opt", option))
@@ -41,6 +43,7 @@
names.only=TRUE)
})),
funct=funct,
+ quote=quote,
option=option
)
Modified: trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/R/rk.plugin.component.R 2013-11-24 23:02:40 UTC (rev 4769)
@@ -128,6 +128,8 @@
include=include,
about=about.node,
gen.info=gen.info)
+ # make sure there's no duplicate IDs
+ stopifnot(rk.uniqueIDs(XML.plugin, bool=TRUE))
slot(this.component, "xml") <- XML.plugin
} else {
slot(this.component, "xml") <- rk.XML.plugin("")
Added: trunk/rkward/packages/rkwarddev/R/rk.uniqueIDs.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rk.uniqueIDs.R (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/rk.uniqueIDs.R 2013-11-24 23:02:40 UTC (rev 4769)
@@ -0,0 +1,37 @@
+#' Check plugin dialogs for duplicate IDs
+#'
+#' A plugin must not have duplicated IDs to work properly. This function
+#' cannot automatically correct duplicates, but it will warn you about
+#' it, so you can correct your plugin script manually
+#'
+#' @param obj An XML object of class XiMpLe.node or XiMpLe.doc.
+#' @param bool Logical, if \code{TRUE} this function will return a logical value.
+#' @param warning Logical, if \code{TRUE} will throw a warning if duplicates were found,
+#' listing the findings.
+#' @return A vector with duplicate IDs, if any were found.
+#' If \code{bool=TRUE} returns a logical value.
+
+rk.uniqueIDs <- function(obj, bool=FALSE, warning=TRUE){
+ allIDs <- XMLScanDeep(obj, find="id", search="attributes")
+ duplicateIDs <- duplicated(allIDs)
+ if(any(duplicateIDs)){
+ # ok, let's get 'em
+ invalidIDs <- unique(allIDs[duplicateIDs])
+ result <- allIDs[allIDs %in% invalidIDs]
+ if(isTRUE(warning)){
+ warning(paste0("Duplicate IDs wer found:\n ", paste0(names(result), ": ", result, collapse="\n ")), call.=FALSE)
+ } else {}
+ if(isTRUE(bool)){
+ return(FALSE)
+ } else {
+ return(result)
+ }
+ } else {
+ if(isTRUE(bool)){
+ return(TRUE)
+ } else {
+ return(invisible(NULL))
+ }
+ }
+}
+
Modified: trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/R/rkwarddev-package.R 2013-11-24 23:02:40 UTC (rev 4769)
@@ -4,7 +4,7 @@
#' Package: \tab rkwarddev\cr
#' Type: \tab Package\cr
#' Version: \tab 0.06-3\cr
-#' Date: \tab 2013-07-05\cr
+#' Date: \tab 2013-11-24\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
@@ -19,6 +19,6 @@
#' @name rkwarddev-package
#' @docType package
#' @title The rkwarddev Package
-#' @author Meik Michalke \email{meik.michalke@@hhu.de}
+#' @author Meik Michalke
#' @keywords package
NULL
Modified: trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/man/rk.plugin.component.Rd 2013-11-24 23:02:40 UTC (rev 4769)
@@ -130,7 +130,7 @@
\examples{
\dontrun{
test.dropdown <- rk.XML.dropdown("mydrop",
- opts=list("First Option"=c(val="val1"),
+ options=list("First Option"=c(val="val1"),
"Second Option"=c(val="val2", chk=TRUE)))
test.checkboxes <- rk.XML.row(rk.XML.col(
list(test.dropdown,
@@ -138,8 +138,8 @@
rk.XML.cbox(label="bar", val="bar2"))
))
test.vars <- rk.XML.vars("select some vars", "vars go here")
-test.tabbook <- rk.XML.dialog(rk.XML.tabbook("My Tabbook", tab.labels=c("First Tab",
- "Second Tab"), children=list(test.checkboxes, test.vars)))
+test.tabbook <- rk.XML.dialog(rk.XML.tabbook("My Tabbook",
+ tabs=c("First Tab"=test.checkboxes, "Second Tab"=test.vars)))
rk.plugin.component("Square the Circle",
xml=list(dialog=test.tabbook))
Added: trunk/rkward/packages/rkwarddev/man/rk.uniqueIDs.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rk.uniqueIDs.Rd (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/rk.uniqueIDs.Rd 2013-11-24 23:02:40 UTC (rev 4769)
@@ -0,0 +1,27 @@
+\name{rk.uniqueIDs}
+\alias{rk.uniqueIDs}
+\title{Check plugin dialogs for duplicate IDs}
+\usage{
+ rk.uniqueIDs(obj, bool = FALSE, warning = TRUE)
+}
+\arguments{
+ \item{obj}{An XML object of class XiMpLe.node or
+ XiMpLe.doc.}
+
+ \item{bool}{Logical, if \code{TRUE} this function will
+ return a logical value.}
+
+ \item{warning}{Logical, if \code{TRUE} will throw a
+ warning if duplicates were found, listing the findings.}
+}
+\value{
+ A vector with duplicate IDs, if any were found. If
+ \code{bool=TRUE} returns a logical value.
+}
+\description{
+ A plugin must not have duplicated IDs to work properly.
+ This function cannot automatically correct duplicates,
+ but it will warn you about it, so you can correct your
+ plugin script manually
+}
+
Modified: trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd 2013-11-13 15:29:02 UTC (rev 4768)
+++ trunk/rkward/packages/rkwarddev/man/rkwarddev-package.Rd 2013-11-24 23:02:40 UTC (rev 4769)
@@ -8,7 +8,7 @@
\details{
\tabular{ll}{ Package: \tab rkwarddev\cr Type: \tab
Package\cr Version: \tab 0.06-3\cr Date: \tab
- 2013-07-05\cr Depends: \tab R (>= 2.9.0),methods,XiMpLe
+ 2013-11-24\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
@@ -18,7 +18,7 @@
structures for RKWard.
}
\author{
- Meik Michalke \email{meik.michalke at hhu.de}
+ Meik Michalke
}
\keyword{package}
More information about the rkward-tracker
mailing list