Learn R Programming

gsubfn (version 0.3-1)

as.function.formula: Make a one-line function from a formula.

Description

Create a function from a formula.

Usage

## S3 method for class 'formula':
as.function(x, ...)

Arguments

x
Formula with no left side.
...
Currently not used.

Value

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

Examples

Run this code
as.function(~ as.numeric(x) + as.numeric(y))
as.function(x + y ~ as.numeric(x) + as.numeric(y)) # same

Run the code above in your browser using DataLab