# Script-class

0th

Percentile

##### The Script class and elements

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").

Keywords
classes, programming
##### Objects from the Class

Objects of class Script are created with readScript.

Objects of class ScriptInfo are created with getInputs or as(, "ScriptInfo").

##### Slots

.Data:

the elements of the list.

location:

a character string that gives the file name or URL of the code for this script.

##### Extends

Class "'>list", from data part. Class "'>vector", by class "list", distance 2.

##### Methods

coerce

signature(from = "Script", to = "ScriptInfo"): convert a Script to a ScriptInfo to access the meta-information

coerce

signature(from = "ScriptNode", to = "ScriptNodeInfo"): compute the meta-information from an individual code element.

readScript

##### Aliases
• Script-class
• AnnotatedScript-class
• ScriptNode-class
• ScriptInfo-class
• ScriptNodeInfo-class
• coerce,Script,ScriptInfo-method
• coerce,ScriptNode,ScriptNodeInfo-method
• coerce,expression,ScriptNodeInfo-method
• coerce,language,ScriptNodeInfo-method
• [,Script,vector,missing-method
• [,Script,character,missing-method
• $,Script-method ##### Examples # NOT RUN { 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")