Description Usage Arguments Examples
This constructs a new function given it's three components: list of arguments, body code and parent environment.
1 | function_new(args, body, env = parent.frame())
|
args |
A named list of default arguments. Note that if you want
arguments that don't have defaults, you'll need to use the special function
|
body |
A language object representing the code inside the function.
Usually this will be most easily generated with |
env |
The parent environment of the function, defaults to the calling
environment of |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | f <- function(x) x + 3
g <- function_new(alist(x = ), quote(x + 3))
# The components of the functions are identical
identical(formals(f), formals(g))
identical(body(f), body(g))
identical(environment(f), environment(g))
# But the functions are not identical because f has src code reference
identical(f, g)
attr(f, "srcref") <- NULL
# Now they are:
stopifnot(identical(f, g))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.