Dapatkan atau atur isi suatu fungsi.
body(fun = sys.function(sys.parent()))
body(fun, envir = environment(fun)) <- value
| Parameter | Deskripsi |
|---|---|
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’. |
# NOT RUN {
body(body)
f <- function(x) x^5
body(f) <- quote(5^x)
## or equivalently body(f) <- expression(5^x)
f(3) # = 125
body(f)
## creating a multi-expression body
e <- expression(y <- x^2, return(y)) # or a list
body(f) <- as.call(c(as.name("{"), e))
f
f(8)
# }
# NOT RUN {
<!-- %% Rd parser bug? : need to backslash-escape the "{" below: -->
# }
# NOT RUN {
## Using substitute() may be simpler than 'as.call(c(as.name("{",..)))':
stopifnot(identical(body(f), substitute({ y <- x^2; return(y) })))
# }