ID EN
Function Utilities

function

R Base 3.6.2

These functions provide the base mechanisms for defining new functions in the R language.

Syntax

R
<code>function( arglist ) expr</code>
<code>return(value)</code>

Arguments

Parameter Description
arglist Empty or one or more name or name=expression terms.
expr An expression.
value An expression.

Details

The names in an argument list can be back-quoted non-standard names (see ‘backquote’). If value is missing, NULL is returned. If it is a single expression, the value of the evaluated expression is returned. (The expression is evaluated as soon as return is called, in the evaluation frame of the function and before any on.exit expression is evaluated.) If the end of a function is reached without calling return, the value of the last evaluated expression is returned.

Examples

Example
R
# NOT RUN {
norm <- function(x) sqrt(x%*%x)
norm(1:4)

## An anonymous function:
(function(x, y){ z <- x^2 + y^2; x+y+z })(0:7, 1)
# }

See Also

args. formals body and environment for accessing the component parts of a function. debug for debugging; using invisible inside return(.) for returning invisibly.