[rkward] packages/rkwarddev: fixed rk.XML.valueslot() and rk.XML.varslot()
m.eik michalke
meik.michalke at uni-duesseldorf.de
Mon Nov 30 14:42:40 UTC 2015
Git commit 45302e96cef2983da9ca0339065e1a583191c9e7 by m.eik michalke.
Committed on 30/11/2015 at 14:42.
Pushed by meikm into branch 'master'.
fixed rk.XML.valueslot() and rk.XML.varslot()
- they both silently ignored source values if they were valid strings, not XiMpLe objects
- added a portion to the vignette
M +3 -1 packages/rkwarddev/ChangeLog
M +6 -6 packages/rkwarddev/R/01_methods_01_plugin2script.R
M +5 -1 packages/rkwarddev/R/rk.XML.valueslot.R
M +5 -1 packages/rkwarddev/R/rk.XML.varslot.R
M +67 -2 packages/rkwarddev/inst/doc/rkwarddev_vignette.Rnw
M +- -- packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf
M +12 -1 packages/rkwarddev/vignettes/rkwarddev_vignette.Rnw
http://commits.kde.org/rkward/45302e96cef2983da9ca0339065e1a583191c9e7
diff --git a/packages/rkwarddev/ChangeLog b/packages/rkwarddev/ChangeLog
index 5076d5e..9a126e6 100644
--- a/packages/rkwarddev/ChangeLog
+++ b/packages/rkwarddev/ChangeLog
@@ -18,6 +18,8 @@ fixed:
lines
- the "i18n" attribute in lists e.g. for rk.XML.radio() didn't really work
- improved indetation for rk.JS.oset objects
+ - rk.XML.varslot() and rk.XML.valueslot() didn't correctly add sources if
+ they were character strings (which is valid)
added:
- new methods plugin2script() to try to translate raw plugin XML into
working rkwarddev script calls
@@ -52,7 +54,7 @@ changed:
- improved error handling in rk.JS.header(), error messages are more
informative now
- rk.uniqueIDs() now checks "dialog" and "wizard" sections separately
- - updated the vignette with information on js() and how to add help pages
+ - updated the vignette with information on js(), plugin2script(), and how to add help pages
- internal function modif.validity() now calls modifiers() to give more
useful feedback
- all functions offering "intent.by" as an option now fetch the default
diff --git a/packages/rkwarddev/R/01_methods_01_plugin2script.R b/packages/rkwarddev/R/01_methods_01_plugin2script.R
index a09c995..9b5b3f3 100644
--- a/packages/rkwarddev/R/01_methods_01_plugin2script.R
+++ b/packages/rkwarddev/R/01_methods_01_plugin2script.R
@@ -77,7 +77,7 @@
#' identical(rkdev.row.row_clmndc1212, test.checkboxes)
setGeneric(
"plugin2script",
- function(obj, prefix="rkdev", indent=TRUE, level=1, drop.defaults=TRUE, node.names=TRUE, collapse="."){
+ function(obj, prefix="", indent=TRUE, level=1, drop.defaults=TRUE, node.names=FALSE, collapse="."){
standardGeneric("plugin2script")
}
)
@@ -89,7 +89,7 @@ setGeneric(
#' @import XiMpLe
setMethod("plugin2script",
signature(obj="XiMpLe.doc"),
- function(obj, prefix="rkdev", indent=TRUE, level=1, drop.defaults=TRUE, node.names=TRUE, collapse=".") {
+ function(obj, prefix="", indent=TRUE, level=1, drop.defaults=TRUE, node.names=FALSE, collapse=".") {
# search for logic, dialog and wizard sections
secLogic <- XMLScan(obj, "logic")
secDialog <- XMLScan(obj, "dialog")
@@ -132,7 +132,7 @@ setMethod("plugin2script",
#' @import XiMpLe
setMethod("plugin2script",
signature(obj="XiMpLe.node"),
- function(obj, prefix="rkdev", indent=TRUE, level=1, drop.defaults=TRUE, node.names=TRUE, collapse=".") {
+ function(obj, prefix="", indent=TRUE, level=1, drop.defaults=TRUE, node.names=FALSE, collapse=".") {
return(p2s(node=obj, indent=indent, level=level, prefix=prefix, drop.defaults=drop.defaults, node.names=node.names, collapse=collapse))
}
)
@@ -144,7 +144,7 @@ setMethod("plugin2script",
#' @import XiMpLe
setMethod("plugin2script",
signature(obj="character"),
- function(obj, prefix="rkdev", indent=TRUE, level=1, drop.defaults=TRUE, node.names=TRUE, collapse=".") {
+ function(obj, prefix="", indent=TRUE, level=1, drop.defaults=TRUE, node.names=FALSE, collapse=".") {
XML.tree <- parseXMLTree(obj)
return(
plugin2script(
@@ -167,7 +167,7 @@ setMethod("plugin2script",
#' @import XiMpLe
setMethod("plugin2script",
signature(obj="connection"),
- function(obj, prefix="rkdev", indent=TRUE, level=1, drop.defaults=TRUE, node.names=TRUE, collapse=".") {
+ function(obj, prefix="", indent=TRUE, level=1, drop.defaults=TRUE, node.names=FALSE, collapse=".") {
XML.tree <- parseXMLTree(obj)
return(
plugin2script(
@@ -411,7 +411,7 @@ p2s.checkTabIDs <- function(node){
## function p2s()
# this is the main work horse, going through nested XML nodes recursively
# called by the actual methods
-p2s <- function(node, indent=TRUE, level=1, prefix="rkdev", drop.defaults=TRUE, node.names=TRUE, collapse="."){
+p2s <- function(node, indent=TRUE, level=1, prefix="", drop.defaults=TRUE, node.names=FALSE, collapse="."){
nodeName <- XMLName(node)
nodeAttrs <- XMLAttrs(node)
# fail if we don't know this node type
diff --git a/packages/rkwarddev/R/rk.XML.valueslot.R b/packages/rkwarddev/R/rk.XML.valueslot.R
index 5a5f5b7..67a3eb8 100644
--- a/packages/rkwarddev/R/rk.XML.valueslot.R
+++ b/packages/rkwarddev/R/rk.XML.valueslot.R
@@ -78,7 +78,11 @@ rk.XML.valueslot <- function(label, source, property=NULL, required=FALSE, multi
value.slot.attr[["source_property"]] <- paste(check.ID(source), property, sep=".")
} else {}
}
- } else {}
+ } else if(is.character(source)){
+ var.slot.attr[["source"]] <- check.ID(source)
+ } else {
+ stop(simpleError("No valid 'source' value given!"))
+ }
if(isTRUE(required)){
value.slot.attr[["required"]] <- "true"
diff --git a/packages/rkwarddev/R/rk.XML.varslot.R b/packages/rkwarddev/R/rk.XML.varslot.R
index 0fae276..87a825b 100644
--- a/packages/rkwarddev/R/rk.XML.varslot.R
+++ b/packages/rkwarddev/R/rk.XML.varslot.R
@@ -88,7 +88,11 @@ rk.XML.varslot <- function(label, source, property=NULL, required=FALSE, multi=F
var.slot.attr[["source_property"]] <- paste(check.ID(source), property, sep=".")
} else {}
}
- } else {}
+ } else if(is.character(source)){
+ var.slot.attr[["source"]] <- check.ID(source)
+ } else {
+ stop(simpleError("No valid 'source' value given!"))
+ }
if(!is.null(classes)){
var.slot.attr[["classes"]] <- paste(classes, collapse=" ")
diff --git a/packages/rkwarddev/inst/doc/rkwarddev_vignette.Rnw b/packages/rkwarddev/inst/doc/rkwarddev_vignette.Rnw
index 72879b6..3d13fa5 100644
--- a/packages/rkwarddev/inst/doc/rkwarddev_vignette.Rnw
+++ b/packages/rkwarddev/inst/doc/rkwarddev_vignette.Rnw
@@ -91,6 +91,7 @@ how you use them will also be explained later on:
\begin{itemize}
\item \texttt{echo()}: Produces an equivalent of the JavaScript \texttt{echo()} function
\item \texttt{id()}: Similar to paste, but replaces \texttt{rkwarddev} objects with their ID value
+ \item \texttt{idq()}: Like \texttt{id}, but also quotes the ID value
\item \texttt{js()}: Short for JavaScript, like \texttt{id()}, but will translate \texttt{if} control structures and some operands directly from R to JavaScript
\item \texttt{qp()}: Short for ''\textbf{q}uote \& \textbf{p}lus``, like \texttt{id()}, but with different replacement defaults
\item \texttt{ite()}: Short for ''\textbf{i}f, \textbf{t}hen, \textbf{e}lse``, a shortcut to generate JavaScript \texttt{if() \{\} else \{\}} conditions
@@ -478,7 +479,7 @@ the condition but translate it into JavaScript code:
As you can see, the resulting JavaScript code is very similar to the \texttt{R} code that created it, so using \texttt{js()} is probably preferable
over \texttt{ite()}. Notice the \texttt{cat()} call here? In contrast to \texttt{ite()} the output of \texttt{js()} is already a character string.
-But \texttt{js()} can do more: It also preserves some ofeten used operators from evaluation, so for instance you can do comparisons in your \texttt{if}
+But \texttt{js()} can do more: It also preserves some often used operators from evaluation, so for instance you can do comparisons in your \texttt{if}
clause:
\begin{Schunk}
@@ -555,7 +556,7 @@ Now the plugin actually changes the generated code if you select an object from
\subsection{Adding help pages}
-To help users understanding your plugin, it is a good practice to add a help page to it, allthoug it is optional, technically.
+To help users understanding your plugin, it is a good practice to add a help page to it, allthough it is optional, technically.
A help starts with a summary and global usage information, and then usually has detailed information on each GUI element of the
plugin dialog. It is very easy to add a help page with \texttt{rkwarddev}, so there is literally no excuse.
@@ -611,6 +612,70 @@ Now the plugin has a working \textit{Help} button which opens a page in the help
\includegraphics{./RKWard_vign_example_help_page.png}
\end{center}
+\section{Turning existing plugins into \texttt{rkwarddev} scripts}
+
+Imagine you already have your (manually written) \texttt{RKWard} plugin, and now would like to continue its development using
+an \texttt{rkwarddev} script. Do you have to rewrite everything from scratch? Fortunately, you don't. And even if you don't want
+to use \texttt{rkwarddev} for further development, the following might still be helpful for you, as it can be used to check
+your plugin code for undetected errors.
+
+The function \texttt{plugin2script()} can be used to go the other way around and generate \texttt{rkwarddev} script code from
+plugin XML code. It is capable of parsing *.xml files or \texttt{XiMpLe} objects. If the parsed code contains invalid
+syntax, you should get a warning, otherwise it returns a character string that can be used in a script to generate the equivalent
+XML code:
+
+ \begin{Schunk}
+ \begin{Sinput}
+> cat(plugin2script(myDialog))
+ \end{Sinput}
+ \begin{Soutput}
+rk.XML.dialog(
+ rkdev.row.row_vCCEXMLEXM <- rk.XML.row(
+ rkdev.varselector.my_vars <- rk.XML.varselector(
+ id.name="my_vars"
+ ),
+ rkdev.column.clm_vCCEXMLEXM <- rk.XML.col(
+ rkdev.varslot.vrsl_Chosvrbl <- rk.XML.varslot(
+ label="Chose a variable",
+ source="my_vars",
+ id.name="vrsl_Chosvrbl"
+ ),
+ rkdev.frame.frm_ExmplXML <- rk.XML.frame(
+ rkdev.checkbox.chc_Checkme <- rk.XML.cbox(
+ label="Check me!",
+ id.name="chc_Checkme"
+ ),
+ rkdev.checkbox.chc_Nocheckm <- rk.XML.cbox(
+ label="No, check me!!!",
+ chk=TRUE,
+ id.name="chc_Nocheckm"
+ ),
+ label="Example XML object",
+ id.name="frm_ExmplXML"
+ ),
+ id.name="clm_vCCEXMLEXM"
+ ),
+ id.name="row_vCCEXMLEXM"
+ ),
+ label="Example dialog"
+)
+ \end{Soutput}
+ \end{Schunk}
+
+This can be optimized, e.\,g., by re-ordering the object defintions without all the nesting,
+replacing the character string \texttt{source="my\_vars"} in \texttt{rk.XML.varslot()} with the varselector object etc.
+But it sure is a good start and saves a lot of typing. Most importantly, the generated XML
+object of this script code is identical to the analyzed object:
+
+ \begin{Schunk}
+ \begin{Sinput}
+> identical(eval(parse(text=plugin2script(myDialog))), myDialog)
+ \end{Sinput}
+ \begin{Soutput}
+[1] TRUE
+ \end{Soutput}
+ \end{Schunk}
+
% \subsection{The whole is more than the sum of its parts}
%
%
diff --git a/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf b/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf
index c6456a5..ecd02c8 100644
Binary files a/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf and b/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf differ
diff --git a/packages/rkwarddev/vignettes/rkwarddev_vignette.Rnw b/packages/rkwarddev/vignettes/rkwarddev_vignette.Rnw
index caafc36..3d13fa5 100644
--- a/packages/rkwarddev/vignettes/rkwarddev_vignette.Rnw
+++ b/packages/rkwarddev/vignettes/rkwarddev_vignette.Rnw
@@ -663,7 +663,18 @@ rk.XML.dialog(
\end{Schunk}
This can be optimized, e.\,g., by re-ordering the object defintions without all the nesting,
-but it sure is a good start and saves a lot of typing.
+replacing the character string \texttt{source="my\_vars"} in \texttt{rk.XML.varslot()} with the varselector object etc.
+But it sure is a good start and saves a lot of typing. Most importantly, the generated XML
+object of this script code is identical to the analyzed object:
+
+ \begin{Schunk}
+ \begin{Sinput}
+> identical(eval(parse(text=plugin2script(myDialog))), myDialog)
+ \end{Sinput}
+ \begin{Soutput}
+[1] TRUE
+ \end{Soutput}
+ \end{Schunk}
% \subsection{The whole is more than the sum of its parts}
%
More information about the rkward-tracker
mailing list