Description Usage Arguments Details Value Note Examples
Partially evaluates a function, returning only the objects which exist after the last line of partial evaluation.
1 |
fun |
A function to partially evaluate. |
args |
A list of the arguments necessary for the function to execute. See details. |
eval_point |
The function line from which to return the result. A line number in the body of the function, or a character string quoting a part of the function. See details. |
full_scope |
Whether to return everything that was in scope at the partial evaluation point, defaults to **FALSE**. |
fix_pattern |
Whether to used **fixed** for regex matching on **eval_point**, defaults to **FALSE**. |
Parameter **args** can be safely ignored for functions which take no arguments explicitly, or for functions that have all their arguments set. **eval_point** stands for the line in the function body to be replaced with a return - this line is temporarily overwritten so a return can be made from it. See examples for usage.
A result of partial evaluations - the full environment containing every object in scope at that evaluation if **full_scope** is **TRUE**, the last **call** otherwise.
If regex matching fails and your expression does not evaluate to anything valid, please try shortening it or supplying a different part of it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # create a dummy function
dummy_function <- function( x, y = 2, z,
a = 5, b = TRUE, c = 10 )
{
x_2 <- x + y - z
TRUTHFULLY <- b
negative <- (c-a) > 0
return(y)
}
# works with function body line number
partial( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = 1 )
partial( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = 3 )
# works with partial string matching
partial( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = "negat" )
# and semi-full string matching
partial( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = "negative <- " )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.