f <- function(x, y) {
if (x > 0) {
x * y;
} else {
y - x;
}
}
b <- body(f);
typeof(b);
#
# "language"
class(b);
#
# "{"
mode(b);
#
# "call"
is.language(b);
#
# TRUE
f(2, 3);
#
# 6
body(f) <- x + y ;
f(2, 3);
body(body);
#
# {
# if (is.character(fun))
# fun <- get(fun, mode = "function", envir = parent.frame())
# .Internal(body(fun))
# }
fun <- function(a, b) {
a * b;
}
bod <- body(fun);
eval(bod, list(a=6, b=7));
#
# 42