sourceVariable | R Documentation |
This function allows the caller to evaluate the code within the
document (or list of code chunks directly) in order to define
one or more variables and then terminate. This is similar
to runUpToSection
but is oriented towards variables
rather than particular code blocks.
sourceVariable(vars, doc, frags = readScript(doc), eval = TRUE, env = globalenv(),
nestedEnvironments = FALSE, verbose = TRUE,
checkLibraries = eval, force = FALSE, first = FALSE,
info = lapply(frags, getInputs))
vars |
the names of the variables which are of interest. This need not include intermediate variables, but instead is the vector of names of the variables that the caller wants defined ultimately. |
doc |
the document containing the code blocks |
frags |
the code fragments |
eval |
whether to evaluate the necessary code blocks or just return them. |
env |
the environment in which to evaluate the code blocks. |
nestedEnvironments |
a logical value indicating whether to evaluate each of the different code blocks within their own environment that is chained to the previous one. |
verbose |
a logical value indicating whether to print the expression being evaluated before it is actually evaluated. |
checkLibraries |
a logical value that controls whether we check
for functions that are not currently available and if there are any
whether we add calls to load libraries in |
force |
a logical value that controls whether we evaluate the
expression to create or update a variable if the variable already
exists in |
first |
a logical value. This is intended to allow running up to the first instance of the variable, not all of them. |
info |
the information about each expression. This is computed automatically, but the caller can specify it to avoid redundant computations. |
If eval
is TRUE
, a list of the results
of evaluating the code blocks. Alternatively,
if eval
is FALSE
, this returns the expressions
constituting the code blocks. In this case, the function is the same
as getVariableDepends
We should add a nestedEnvironments
parameter as in
runUpToSection. In fact, consolidate the code so it can be shared.
Duncan Temple Lang
getVariableDepends
f = system.file("samples", "dual.R", package = "CodeDepends")
e = readScript(f)
getVariableDepends("k", frags = e)
sourceVariable("k", frags = e, verbose = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.