Create a custom input collector which will be used by getInputs to process to collect various aspects of the code as it is being processed. Custom collector functions can be specified which will be called when a particular function is called within the code.One major use for this is leveraging knowledge of specific functions' behavior to track side effects relevant to a particular use-case.
inputCollector(..., functionHandlers = list(...), inclPrevOutput =
FALSE, checkLibrarySymbols = FALSE, funcsAsInputs = checkLibrarySymbols)
Custom information collection functions. Argument names correspond to
R functions, with the custom collection function being called when a
call to the named function is detected within the code being
processed. Overridden by functionHandlers
A named list of custom collection functions.
Should variables which were output previously
within the code be treated as inputs in subsequent expressions. If
TRUE
each expression within the code is treated separately
with respect to detecting input variables, if FALSE
the code
is treated as a single block. Defaults to FALSE
If TRUE
symbols exported by default
package and packages loaded within the code via library
or
require
calls are tracked and excluded from the list of input
variables. Defaults toFALSE
If TRUE
functions called by the code being
processed are treated as input variables and listed as
such. Defaults to the value of checkLibrarySymbols
. A value
of funcsAsInputs
which does not agree with the value of
checkLibrarySymbols
is NOT recommended.
A list of functions used to update internal tracking variables (see Details) as well as the following:
Each custom collection function should accept three arguments:
the code or expression currently being processed
the current inputCollector
the base directory in which the processing is taking place, e.g. to determine whether strings correspond to files
These functions should process the expression and then use
collector
's collection functions and/or the <<-
assignment operator to update the lists of found entities.
Currently trackable entities, updatable by <entity><<-c(<entity>,
value)
or as specified, include:
libraries loaded by the code via library
or
require
. Updatable by calling collector$library
symbols exported by available libraries. Tracked
automatically within collector$library
string constants which correspond to an existing file in
basedir
. Tracked automatically when strings are passed to
collector$string
string constants which do not correspond to existing
files. Tracked automatically when strings are passed to
collector$string
all variable names used in the code. Updatable by calling
collector$vars
with input
as TRUE
or FALSE
as appropriate
variable names which are assigned to in the code (input
variables). Updatable by calling collector$set
or
collector$vars
with input=TRUE
functions called by the code. Updatable by calling
collector$calls
. This will also update vars
if the
collector was created with funcsAsInputs=TRUE
variables removed by the vode via calls to
collector$removes
variables which have had elements within them updated,
e.g. via x$foo <- bar
. Updatable via calls to
collector$update
side effects generated by the code. Experimental,
default side effect detection should not be assumed to be robust or
exhaustive. Updatable via calls to sideEffects
If formulaInputs
is FALSE
within
the call to getInputs, this tracks variables which appear within
formulas, otherwise this is unused and such variables are treated as
input. Updatable via the modelVars argument in calls to
collector$addInfo
'>ScriptNodeInfo
getInputs
# NOT RUN {
f = system.file("samples", "results-multi.R", package="CodeDepends")
sc = readScript(f)
collector = inputCollector(library = function(e, collector, basedir, ...)
{
print(paste("loaded library", e[[2]]))
collector$library(as.character(e[[2]]))
})
res = getInputs(sc, collector = collector )
#[1] "loaded library splines"
#[1] "loaded library tsModel"
# }
Run the code above in your browser using DataCamp Workspace