f <- function(x, y){x + y}
f_ <- section_fun(f, list(y = 10), method="args") ## "def"" is default
f_ <- section_fun(f, nms="y", vls=10, method="args") ## SAME AS ABOVE
f_
f_(x=1)
f_ <- section_fun(f, list(y = 10), method="body") ##
f_ <- section_fun(f, nms="y", vls=10, method="body") ## SAME AS ABOVE
f_
f_(x=1)
f_ <- section_fun(f, list(y = 10), method="env")
f_ <- section_fun(f, nms="y", vls=10, method="env") ## SAME AS ABOVE
f_
f_(x=1)
get_section(f_)
get_fun(f_)
## With more complicated values:
g <- function(A, B) {
A + B
}
g_ <- section_fun(g, list(A = matrix(1:4, nrow=2)))
g_ <- section_fun(g, "A", list(matrix(1:4, nrow=2)))
g_(diag(1, 2))
g_ <- section_fun(g, list(A = matrix(1:4, nrow=2)))
## Using built in function
set.seed(123)
rnorm5 <- section_fun(rnorm, list(n=5))
rnorm5(0, 1)
set.seed(123)
rnorm(5)
Run the code above in your browser using DataLab