View source: R/modifyCodeWalker.R
mkModifyCodeWalker | R Documentation |
mkModifyCodeWalker
generates a code-walker object
that can be passed to walkCode
.
Rather than analyzing code, this actively rewrites code and
assembles the results to create a modified version of the code
passed to walkCode
.
The other functions are simple generator-functions
that take information and return a function that
does any rewriting of each code element it is passed.
The result of these are passed as the rewrite
argument of mkModifyCodeWalker
.
These are closure generators and helper functions.
mkModifyCodeWalker(rewrite = function(x, ...) x, skipIfFalse = TRUE, mkLiteralMap = FALSE, ..., verbose = FALSE)
genAddArgsToCalls(funArgs)
genRemoveCode(pred)
genRewriteVars(names)
rewrite |
a function that is called with
the current language element (and the code walker object)
and can return that object or a modified version of it
to be inserted into the updated code.
Alternatively, it can return |
skipIfFalse |
a scalar logical indicating whether to skip or descend into |
mkLiteralMap |
a scalar logical. This is likely to be moved. For now it helps avoid any errors in less-tested code. |
... |
additional arguments |
verbose |
a scalar logical controlling whether verbose messages about the processing are displayed on the console. Useful only for debugging/understanding. |
funArgs |
a list of character vectors, one for each of the functions to whose calls need to be updated in the original function(s). Ideally these should be named character mapping the names of the new parameters to arguments. |
pred |
a function that identifies which language objects (typically |
names |
a named-character vector. The names identify the names of current/existing variables and the corresponding values give the new names to which these should be mapped. |
An object which is list of functions that can be passed to walkCode
.
Duncan Temple Lang
codetools
There are several higher level functions that use this low-level mechanism,
e.g., extractFunctions
, mkGlobalsLocal
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.