
Last chance! 50% off unlimited learning
Sale ends in
function( arglist ) expr
return(value)
formals
(its argument
list), its body
(expr
in the ‘Usage’
section) and its environment
which provides the
enclosure of the evaluation frame when the closure is used. There is an optional further component if the closure has been
byte-compiled. This is not normally user-visible, but it indicated
when functions are printed. 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.
args
. formals
, body
and
environment
for accessing the component parts of a
function.
debug
for debugging; using invisible
inside
return(.)
for returning invisibly.
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)
Run the code above in your browser using DataLab