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).

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
#> arg
f2(.(arg)) # returns "USER_ARG" (character)
#> [1] "USER_ARG"
f2(.(-arg)) # returns USER_ARG (name)
#> USER_ARG