# NOT RUN {
old.options <- options(keep.source = FALSE)
as.function(~ as.numeric(x) + as.numeric(y))
as.function(x + y ~ as.numeric(x) + as.numeric(y)) # same
as.function(~ ..1 + ..2)
# the replacement function in gsubfn uses as.function.formula to
# interpret formulas as functions. Here we insert ! after each digit.
gsubfn("[0-9]", ~ paste0(`&`, "!"), "ab4cd5")
# }
# NOT RUN {
# example where function body must be surrounded with {...}
# due to use of <<-. See warning section above.
assign("mywarn", NULL, .GlobalEnv)
fn$tryCatch( warning("a warning"),
warning = w ~ { mywarn <<- conditionMessage(w)})
print(mywarn)
# }
# NOT RUN {
options(old.options)
# }
Run the code above in your browser using DataLab