rk.JS.vars: Define variables in JavaScript code

View source: R/rk.JS.vars.R

rk.JS.varsR Documentation

Define variables in JavaScript code

Description

Define variables in JavaScript code

Usage

rk.JS.vars(
  ...,
  var.prefix = NULL,
  modifiers = NULL,
  default = FALSE,
  join = "",
  check.modifiers = TRUE,
  getter = "getValue",
  guess.getter = FALSE,
  object.name = FALSE,
  methods = ""
)

Arguments

...

Either one or more character strings (the names of the variables to define), or objects of class XiMpLe.node with plugin XML nodes (whose ID will be extracted and used).

var.prefix

A character string. will be used as a prefix for the JS variable names.

modifiers

A character vector with modifiers you'd like to apply to the XML node property.

default

Logical, if TRUE the default value (no special modifier) of the node will also be defined. Does nothing if modifiers=NULL.

join

A character string, useful for GUI elements which accept multiple objects (e.g., multi-varslots). If join is something other than "", these objects will be collapsed into one string when pasted, joined by this string.

check.modifiers

Logical, if TRUE the given modifiers will be checked for validity. Should only be turned off if you know what you're doing.

getter

A character string, naming the JavaScript function which should be used to get the values in the actual plugin. Depending on the XML element, "getString", "getBool" or "getList" can be useful alternatives. For backwards compatibility, the default is set to "getValue".

guess.getter

Logical, if TRUE try to get a good default getter function for JavaScript variable values.

object.name

Logical, if TRUE the JS variable name will roughly match the R object name. If the object name contains dots, they will be removed and the JS name printed in camel code instead. Use this option with great caution and do not combine it with rk.JS.scan, as it will likely result in unusable code. rk.JS.scan examines XML nodes and therefore does not know any R object names.

methods

An optional character vector of method calls to append to the getter function (see rk.JS.method).

Value

An object of class rk.JS.var.

Note

To get a list of the implemented modifiers in this package see modifiers.

See Also

rk.JS.array, echo, id, modifiers, rk.JS.method and the Introduction to Writing Plugins for RKWard

Examples

# create three checkboxes
checkA <- rk.XML.cbox(label="Run Test A", value="A")
checkB <- rk.XML.cbox(label="Run Test B", value="B")
checkC <- rk.XML.cbox(label="Run Test C", value="C")
# define them by their ID in JavaScript
cat(rk.paste.JS(rk.JS.vars(list(checkA, checkB, checkC))))

rkward-community/rkwarddev documentation built on May 9, 2022, 3:02 p.m.