bquote_function {wrapr} | R Documentation |
Adapt a function to use bquote on its arguments.
Description
bquote_function is for adapting a function defined elsewhere for bquote-enabled argument substitution.
Re-write call to evaluate expr
with bquote
.()
substitution.
Uses convetion that := is considered a alias for =.
Including .(-x)
promoting x
's value from character to a name,
which is called "quote negation" (hence the minus-sign).
Usage
bquote_function(fn)
Arguments
fn |
function to adapt, must have non-empty formals(). |
Value
new function.
See Also
Examples
if(requireNamespace('graphics', quietly = TRUE)) {
angle = 1:10
variable <- as.name("angle")
plotb <- bquote_function(graphics::plot)
plotb(x = .(variable), y = sin(.(variable)))
}
f1 <- function(x) { substitute(x) }
f2 <- bquote_function(f1)
arg <- "USER_ARG"
f2(arg) # returns arg
f2(.(arg)) # returns "USER_ARG" (character)
f2(.(-arg)) # returns USER_ARG (name)
[Package wrapr version 2.1.0 Index]