| Script-class | R Documentation |
This package works with collections of expressions
or code blocks and such a sequence can be thought of as a script.
The Script class is a list of code elements.
Such objects are typically created via a call to
readScript.
They can be read from XML files, tangled Sweave output,
regular R source files and R source files that are annotated
to identify the general task of each code block.
This last type of script has its own class named
AnnotatedScript and the code elements are annotated with labels
such as dataInput, simulate, plot, model, eda and so on.
Each element of a Script list represents code.
These are stored as objects of class ScriptNode.
A ScriptNode class has slots for the
code, the taskType indicating the high-level nature of
the code, and an id so we can easily refer to it.
While our focus is on the code elements in a Script, we work
with meta-data about the code elements. We identify information such
as the input variables required by a code element, the variables it
assigns (the outputs) and so on. This information is stored
in a ScriptNodeInfo object.
And a collection of such objects that parallels a script
is a ScriptInfo object.
We can easily map a Script or a ScriptNode
to the corresponding meta-information via the coercion methods
as(script, "ScriptInfo") and as(node, "ScriptNodeInfo").
Objects of class Script are created with
readScript.
Objects of class ScriptInfo are created with
getInputs or as(, "ScriptInfo").
.Data:the elements of the list.
location:a character string that gives the file name or URL of the code for this script.
Class "list", from data part.
Class "vector", by class "list", distance 2.
signature(from = "Script", to = "ScriptInfo"):
convert a Script to a ScriptInfo to access the meta-information
signature(from = "ScriptNode", to =
"ScriptNodeInfo"):
compute the meta-information from an individual code element.
Duncan Temple Lang
readScript
f = system.file("samples", "results-multi.R", package = "CodeDepends")
sc = readScript(f)
info = as(sc, "ScriptInfo")
info = getInputs(sc, basedir = dirname(f))
# Providing our own handler for calls to source()
sourceHandler = function(e, collector = NULL, basedir = ".", ...) {
collector$string(e[[2]], , TRUE)
collector$calls(as.character(e[[1]]))
}
h = CodeDepends:::inputCollector(source = sourceHandler)
info = getInputs(sc, h, basedir = dirname(f))
## Not run:
u = url("http://www.omegahat.net/CodeDepends/formula.R")
sc = readScript(u)
as(sc, "ScriptInfo")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.