XiMpLe-methods: Generate script code from XML objects

plugin2scriptR Documentation

Generate script code from XML objects

Description

These methods try to translate plugin XML objects into rkwarddev function calls.

Usage

plugin2script(
  obj,
  prefix = "",
  indent = TRUE,
  level = 1,
  drop.defaults = TRUE,
  node.names = FALSE,
  collapse = ".",
  update = NULL
)

## S4 method for signature 'XiMpLe.doc'
plugin2script(
  obj,
  prefix = "",
  indent = TRUE,
  level = 1,
  drop.defaults = TRUE,
  node.names = FALSE,
  collapse = ".",
  update = NULL
)

## S4 method for signature 'XiMpLe.node'
plugin2script(
  obj,
  prefix = "",
  indent = TRUE,
  level = 1,
  drop.defaults = TRUE,
  node.names = FALSE,
  collapse = ".",
  update = NULL
)

## S4 method for signature 'character'
plugin2script(
  obj,
  prefix = "",
  indent = TRUE,
  level = 1,
  drop.defaults = TRUE,
  node.names = FALSE,
  collapse = ".",
  update = NULL
)

## S4 method for signature 'connection'
plugin2script(
  obj,
  prefix = "",
  indent = TRUE,
  level = 1,
  drop.defaults = TRUE,
  node.names = FALSE,
  collapse = ".",
  update = NULL
)

Arguments

obj

Either a character vector (path to a plugin XML file to parse), a connection, an already parsed XML tree (class XiMpLe.doc) or a single XiMpLe.node object.

prefix

Character string, used as the prefix for the object names used in the script. Set to "" to disable the prefix.

indent

Logical, whether the script code should be indented properly.

level

Integer number, the starting leven of indentation.

drop.defaults

Logical, whether to check for the default options in function calls. If the parsed and translated XML code resulted in default options, they are omitted in the resulting script.

node.names

Logical, whether the node names should become part of the generated R object names.

collapse

Character string, used to collapse the parts of the generated R object names.

update

A named list, previous result of a plugin2script call to be updated, e.\,.g., to add the content of a help file to a previously scanned XML file.

Details

They are intended to make it easier to translate previously manually maintained plugin code into rkwarddev scripts. The generated output should not be used as-is, but restructured properly into a useful script.

You can either use a full XML document (read with parseXMLTree) or single (also nested) XiMpLe XML nodes. If you provide a character string, it is assumed to be the full path to a document to be parsed with parseXMLTree and then analysed. Connections are also accepted.

Value

Either a character vector (if obj is a single XML node) or a list of character vectors named "logic", "dialog", "wizard", "summary", "usage", "settings", "related", "technical", "dependencies", "dependency_check", "about", "require", "components", and "hierarchy" (if obj is a full XML document).

Note

The methods might fail, especially with highly complex plugins. Try to break these into sensible chunks and try those speparately. Sometimes, slightly changing the input file might also do the trick to get some usable results.

Examples

## Not run: 
# full XML documents
rkwarddevScript <- plugin2script("~/RKWardPlugins/plugins/myPlugin.xml")
rkwarddevScript <- plugin2script("~/RKWardPlugins/plugins/myPlugin.rkh",
      update=rkwarddevScript)
rkwarddevScript <- plugin2script("~/RKWardPlugins/myPlugin.pluginmap",
      update=rkwarddevScript)
sapply(rkwarddevScript, cat)

## End(Not run)

# single XML node
(test.checkboxes <- rk.XML.row(
  rk.XML.col(
    list(
      rk.XML.cbox(label="foo", value="foo1", chk=TRUE),
      rk.XML.cbox(label="bar", value="bar2")
    )
  )
))
rkwarddevScript <- plugin2script(test.checkboxes)
# see the generated script code
cat(rkwarddevScript)

# we can evaluate the generated code to check whether original
# XML and the newly generated one are identical
eval(parse(text=rkwarddevScript))
identical(row_clmndc1212, test.checkboxes)

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