Description Usage Arguments Details Note Examples
Partially evaluates a function, returning only the objects which exist after the last line of partial evaluation and compares them to expected output
1 | partial_test(fun, args, eval_point, compare_fun = NULL, compare_object = NULL)
|
fun |
A function to partially evaluate (either the function object, or a string). |
args |
A list of the arguments necessary for the function to execute, or nothing. If nothing default parameter values must be specified in the function signature. |
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. |
compare_fun |
A predicate function to compare to, defaults to NULL. |
compare_object |
An object to compare to, defaults to NULL. |
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. The object to return is then compared, either using any form of predicate function, or using an object to compare to. If both function and object are used, the object is compared to the result of the partial evaluation using the same function. See examples for usage.
If regex matching fails and your expression does not evaluate to anything valid, please try shortening it or supplying a different part of it. (Or specifying the correct line number.)
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 28 29 30 31 32 33 | # 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_test( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = 1,
compare_object = NA)
partial_test( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = 3,
compare_object = FALSE)
# works with partial string matching
partial_test( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = "negat",
compare_object = TRUE )
# and semi-full string matching
partial_test( fun = dummy_function,
args = list(x = 10,z = FALSE, b = FALSE),
eval_point = "negative <- ",
compare_object = TRUE )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.