rk.JS.optionset: Evaluate optionset objects in plugin JavaScript

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

rk.JS.optionsetR Documentation

Evaluate optionset objects in plugin JavaScript

Description

This function scans an object generated by rk.XML.optionset, extract IDs of all optioncolumn objects and nest the JavaScript code you define via ... inside a for loop that iterates through all columns. Inside ..., you can use the column objects of rk.XML.optioncolumn to refer to the respective column, rk.JS.optionset will use appropriate variables.

Usage

rk.JS.optionset(
  optionset,
  ...,
  loopvar = "i",
  collapse = ",\\n\\t",
  vars = FALSE,
  guess.getter = TRUE
)

Arguments

optionset

A XiMpLe.node object, the full <optionset> node.

...

The JavaScript code, optionally including the optioncolumn objects. This will become the body of the for loop.

loopvar

Character, name of the index variable used in the for loop.

collapse

Character string, how all optioncolumns should be concatenated on the R code level Hint: To place each one on a new line with tab indentation, set collapse=", \n\t".

vars

Logical, if TRUE all optioncolumn varaibles will be defined first. This is not needed if rk.JS.scan was already called.

guess.getter

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

Details

In case you simply want to define the variables, but not run the loop yet, set vars=TRUE and leave ... empty.

See Also

rk.XML.optionset, rk.XML.optioncolumn

Examples

# this example is taken from the plugin skeleton script
# first set up an optionset object
dep.optionset.packages <- rk.XML.optionset(
  content=rk.XML.frame(rk.XML.stretch(before=list(
    rk.XML.row(
      dep.pckg.name <- rk.XML.input("Package"),
      dep.pckg.min <- rk.XML.input("min"),
      dep.pckg.max <- rk.XML.input("max"),
      dep.pckg.repo <- rk.XML.input("Repository")
    )
  )), label="Depends on R packages"),
  optioncolumn=list(
    dep.optioncol.pckg.name <- rk.XML.optioncolumn(connect=dep.pckg.name,
      modifier="text"),
    dep.optioncol.pckg.min <- rk.XML.optioncolumn(connect=dep.pckg.min, modifier="text"),
    dep.optioncol.pckg.max <- rk.XML.optioncolumn(connect=dep.pckg.max, modifier="text"),
    dep.optioncol.pckg.repo <- rk.XML.optioncolumn(connect=dep.pckg.repo, modifier="text")
  )
)

# now translate it to JavaScript for loop
JS.optionset <- rk.JS.optionset(dep.optionset.packages,
  echo("c("),
  echo("name=\"", dep.optioncol.pckg.name, "\""),
  ite(dep.optioncol.pckg.min, echo(", min=\"", dep.optioncol.pckg.min, "\"")),
  ite(dep.optioncol.pckg.max, echo(", max=\"", dep.optioncol.pckg.max, "\"")),
  ite(dep.optioncol.pckg.repo, echo(", repository=\"", dep.optioncol.pckg.repo, "\"")),
  echo(")")
)

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