substituteDefaultValues | R Documentation |
This function creates a modified version of the specified function by adding code to compute the default value of each parameter just before it is first used. This facilitates compiling code and code analysis to determine global variables correctly. It honors lazy evaluation by not evaluating the code until the variable is referenced.
substituteDefaultValues(f, removeDefaults = TRUE,
sc = new("Script", as.list(body(f))[-1]), info = getInputs(sc))
f |
the function to process |
removeDefaults |
a logical value that controls whether we remove
the original default value expressions in the |
sc |
a |
info |
like |
A function. This is the modified version of the original function.
It is possible that the semantics of the new function
may differ from the original version in the case
that the order of evaluation of the arguments
may be different.
This might occur in the case that two arguments
are missing and we evaluate their default values
in a specific order that is different from how
they are evaluated in the actual call to another function.
For example, in foo(x, y)
, with x
and y
missing in the calling function, we would first evaluate x
and
then y
via their default via expressions.
However, if foo(x, y)
actually uses y
first, then
our order would be incorrect.
Duncan Temple Lang
getGlobals
g =
function(a = x, b = y)
{
x = 1
y = 2
a + b * (x + y)
}
substituteDefaultValues(g)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.