Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

body: Access to and Manipulation of the Body of a Function

bodyR Documentation

Access to and Manipulation of the Body of a Function

Description

Get or set thebody of a function which is basically all ofthe function definition but its formal arguments (formals),see the ‘Details’.

Usage

body(fun = sys.function(sys.parent()))body(fun, envir = environment(fun)) <- value

Arguments

fun

a function object, or see ‘Details’.

envir

environment in which the function should be defined.

value

an object, usually a language object: see section‘Value’.

Details

For the first form,fun can be a character stringnaming the function to be manipulated, which is searched for from theparent frame. If it is not specified, the function callingbody is used.

The bodies of all but the simplest are braced expressions, that iscalls to{: see the ‘Examples’ section for how tocreate such a call.

Value

body returns the body of the function specified. This isnormally a language object, most often a call to{, butit can also be asymbol such aspi or a constant(e.g.,3 or"R") to be the return value of the function.

The replacement form sets the body of a function to theobject on the right hand side, and (potentially) resets theenvironment of the function, and dropsattributes. Ifvalue is of class"expression" the first element is used as the body: anyadditional elements are ignored, with a warning.

See Also

The three parts of a (non-primitive) function are itsformals,body, andenvironment.

Further, seealist,args,function.

Examples

body(body)f <- function(x) x^5body(f) <- quote(5^x)## or equivalently  body(f) <- expression(5^x)f(3) # = 125body(f)## creating a multi-expression bodye <- expression(y <- x^2, return(y)) # or a listbody(f) <- as.call(c(as.name("{"), e))ff(8)## Using substitute() may be simpler than 'as.call(c(as.name("{",..)))':stopifnot(identical(body(f), substitute({ y <- x^2; return(y) })))

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp