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

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Sun Dec 11 22:15:51 UTC 2011


Revision: 4102
          http://rkward.svn.sourceforge.net/rkward/?rev=4102&view=rev
Author:   m-eik
Date:     2011-12-11 22:15:51 +0000 (Sun, 11 Dec 2011)
Log Message:
-----------
rkwarddev: added function tf() to generate common JavaScript code from checkbox objects

Modified Paths:
--------------
    trunk/rkward/packages/rkwarddev/ChangeLog
    trunk/rkward/packages/rkwarddev/DESCRIPTION
    trunk/rkward/packages/rkwarddev/NAMESPACE
    trunk/rkward/packages/rkwarddev/inst/doc/rkwarddev_vignette.pdf

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

Modified: trunk/rkward/packages/rkwarddev/ChangeLog
===================================================================
--- trunk/rkward/packages/rkwarddev/ChangeLog	2011-12-11 18:42:48 UTC (rev 4101)
+++ trunk/rkward/packages/rkwarddev/ChangeLog	2011-12-11 22:15:51 UTC (rev 4102)
@@ -1,6 +1,7 @@
 ChangeLog for package rkwarddev
 
 ## 0.04-12 (2011-12-11)
+  - added function tf() for even quicker JavaScript code generation from checkboxes
   - fixed issue with "about" not being an XML node in rk.plugin.skeleton()
 
 ## 0.04-11 (2011-12-10)

Modified: trunk/rkward/packages/rkwarddev/DESCRIPTION
===================================================================
--- trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-12-11 18:42:48 UTC (rev 4101)
+++ trunk/rkward/packages/rkwarddev/DESCRIPTION	2011-12-11 22:15:51 UTC (rev 4102)
@@ -99,3 +99,4 @@
     'rk.XML.vars.R'
     'rk.XML.wizard.R'
     'show-methods.R'
+    'tf.R'

Modified: trunk/rkward/packages/rkwarddev/NAMESPACE
===================================================================
--- trunk/rkward/packages/rkwarddev/NAMESPACE	2011-12-11 18:42:48 UTC (rev 4101)
+++ trunk/rkward/packages/rkwarddev/NAMESPACE	2011-12-11 22:15:51 UTC (rev 4102)
@@ -77,4 +77,5 @@
 export(rk.XML.varselector)
 export(rk.XML.varslot)
 export(rk.XML.wizard)
+export(tf)
 import(methods)

Added: trunk/rkward/packages/rkwarddev/R/tf.R
===================================================================
--- trunk/rkward/packages/rkwarddev/R/tf.R	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/R/tf.R	2011-12-11 22:15:51 UTC (rev 4102)
@@ -0,0 +1,65 @@
+#' Replace checkbox XML objects with JavaScript code
+#' 
+#' This function is a basically shortcut for \code{\link[rkwarddev:ite]{ite}} with some assumptions.
+#' It's thought to be used when a checkbox should turn an option of an R function to a specified value,
+#' by default \code{TRUE} or \code{FALSE} (hence the name, abbreviated "true or false").
+#' The same result can be obtained with \code{ite}, but for most common cases \code{tf} is much quicker.
+#' 
+#' @param cbox An obkect of class \code{XiMpLe.node} containing a \code{<checkbox>} node, as generated
+#'		by \code{\link[rkwarddev:rk.XML.cbox]{rk.XML.cbox}}.
+#' @param true Logical or character, the value the option should get. E.g., if \code{true=TRUE} then the option will be
+#'		set to \code{TRUE} if the box is checked, or in case \code{not=TRUE}, if the box is not checked.
+#' @param not Logical, inverses the checked status of the checkbox. In other words, set this to \code{TRUE}
+#'		if you want the option to be set if the box is not checked.
+#' @param ifelse Logical, whether the the options should be set anyway. By default, the option will only
+#'		be set in one condition. If \code{ifelse=TRUE}, it will get the inverse value in case of the alternative
+#'		condition, e.g. it will be set to either \code{not=TRUE} or \code{not=FALSE} if the box is checked or unchecked.
+#' @param false Logical or character, the value the option should, only used get if \code{ifelse=TRUE} as well.
+#'		E.g., if \code{false=FALSE} then the option will be set to \code{FALSE} if the box is not checked,
+#'		or in case \code{not=TRUE}, if the box is checked.
+#' @param opt A character string, naming the R option o be set. If \code{NULL}, the XML ID of the checkbox node
+#'		will be used.
+#' @param prefix A character string, what should be pasted before the actual option string. Default is a
+#'		comma and a newline.
+#' @param level Integer, which indentation level to use, minimum is 1.
+#' @param indent.by A character string defining the indentation string to use. This refers to the genrated R code,
+#' 	not the JavaScript code. Indentation is added after the prefix and before the option string.
+#' @return An object of class \code{rk.JS.ite}.
+#' @export
+#' @seealso \code{\link[rkwarddev:ite]{ite}},
+#'		\code{\link[rkwarddev:echo]{echo}},
+#'		\code{\link[rkwarddev:id]{id}},
+#'		and the \href{help:rkwardplugins}{Introduction to Writing Plugins for RKWard}
+#' @examples
+#' # an example checkbox XML node
+#' cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="foo_option")
+#' tf(cbox1)
+
+tf <- function(cbox, true=TRUE, not=FALSE, ifelse=FALSE, false=FALSE, opt=NULL, prefix=",\n", level=3, indent.by="\t"){
+
+	# check if we're given a checkbox, alright...
+	if(inherits(cbox, "XiMpLe.node")){
+		node.name <- cbox at name
+		if(!identical(node.name, "checkbox")){
+			stop(simpleError(paste("Invalid XML node, expected 'checkbox' and got: ", node.name, sep="")))
+		} else {}
+	} else {
+		stop(simpleError("'cbox' must be of class XiMpLe.node!"))
+	}
+
+	if(is.null(opt)){
+		opt.name <- id(cbox, js=FALSE)
+	} else {
+		opt.name <- opt
+	}
+
+	full.prefix <- paste(prefix, indent(level=level, by=indent.by), sep="")
+
+	# check for negation
+	inverse <- ifelse(not, "!", "")
+	result <- ite(id(inverse, cbox),
+		echo(paste(full.prefix, opt.name, "=", true, sep="")),
+		ifelse(ifelse, echo(paste(full.prefix, opt.name, "=", false, sep="")), "")
+		)
+	return(result)
+}

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

Added: trunk/rkward/packages/rkwarddev/man/tf.Rd
===================================================================
--- trunk/rkward/packages/rkwarddev/man/tf.Rd	                        (rev 0)
+++ trunk/rkward/packages/rkwarddev/man/tf.Rd	2011-12-11 22:15:51 UTC (rev 4102)
@@ -0,0 +1,77 @@
+\name{tf}
+\alias{tf}
+\title{Replace checkbox XML objects with JavaScript code}
+\usage{
+  tf(cbox, true = TRUE, not = FALSE, ifelse = FALSE,
+    false = FALSE, opt = NULL, prefix = ",\n", level = 3,
+    indent.by = "\t")
+}
+\arguments{
+  \item{cbox}{An obkect of class \code{XiMpLe.node}
+  containing a \code{<checkbox>} node, as generated by
+  \code{\link[rkwarddev:rk.XML.cbox]{rk.XML.cbox}}.}
+
+  \item{true}{Logical or character, the value the option
+  should get. E.g., if \code{true=TRUE} then the option
+  will be set to \code{TRUE} if the box is checked, or in
+  case \code{not=TRUE}, if the box is not checked.}
+
+  \item{not}{Logical, inverses the checked status of the
+  checkbox. In other words, set this to \code{TRUE} if you
+  want the option to be set if the box is not checked.}
+
+  \item{ifelse}{Logical, whether the the options should be
+  set anyway. By default, the option will only be set in
+  one condition. If \code{ifelse=TRUE}, it will get the
+  inverse value in case of the alternative condition, e.g.
+  it will be set to either \code{not=TRUE} or
+  \code{not=FALSE} if the box is checked or unchecked.}
+
+  \item{false}{Logical or character, the value the option
+  should, only used get if \code{ifelse=TRUE} as well.
+  E.g., if \code{false=FALSE} then the option will be set
+  to \code{FALSE} if the box is not checked, or in case
+  \code{not=TRUE}, if the box is checked.}
+
+  \item{opt}{A character string, naming the R option o be
+  set. If \code{NULL}, the XML ID of the checkbox node will
+  be used.}
+
+  \item{prefix}{A character string, what should be pasted
+  before the actual option string. Default is a comma and a
+  newline.}
+
+  \item{level}{Integer, which indentation level to use,
+  minimum is 1.}
+
+  \item{indent.by}{A character string defining the
+  indentation string to use. This refers to the genrated R
+  code, not the JavaScript code. Indentation is added after
+  the prefix and before the option string.}
+}
+\value{
+  An object of class \code{rk.JS.ite}.
+}
+\description{
+  This function is a basically shortcut for
+  \code{\link[rkwarddev:ite]{ite}} with some assumptions.
+  It's thought to be used when a checkbox should turn an
+  option of an R function to a specified value, by default
+  \code{TRUE} or \code{FALSE} (hence the name, abbreviated
+  "true or false"). The same result can be obtained with
+  \code{ite}, but for most common cases \code{tf} is much
+  quicker.
+}
+\examples{
+# an example checkbox XML node
+cbox1 <- rk.XML.cbox(label="foo", value="foo1", id.name="foo_option")
+tf(cbox1)
+}
+\seealso{
+  \code{\link[rkwarddev:ite]{ite}},
+  \code{\link[rkwarddev:echo]{echo}},
+  \code{\link[rkwarddev:id]{id}}, and the
+  \href{help:rkwardplugins}{Introduction to Writing Plugins
+  for RKWard}
+}
+

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