as.function.formula {gsubfn} | R Documentation |
Create a function from a formula.
## S3 method for class 'formula': as.function(x, ...)
x |
Formula with no left side. |
... |
Currently not used. |
A function is returned whose formal arguments are the
variables in the left hand side, whose body
is the expression on the right side of the formula and whose
environment is the environment of the formula. If there is
no left hand side the free variables on the right, in the
order encountered are used as the arguments. letters
,
LETTERS
and pi
are ignored and not used as arguments.
If the left hand side is 0
then the function is created as
a zero argument function.
->
, ->>
, =
, <-
, <<-
and ?
all have lower operator precdence than ~
so function bodies that
contain them typically must be surrounded with {...}
.
as.function(~ as.numeric(x) + as.numeric(y)) as.function(x + y ~ as.numeric(x) + as.numeric(y)) # same ## 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) ## End(Not run)