fn_new

0th

Percentile

Create a function by "hand"

This constructs a new function given it's three components: list of arguments, body code and parent environment.

Usage
fn_new(args, body, env = env_caller())
Arguments
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 alist, e.g. alist(a = , b = 1)
body
A language object representing the code inside the function. Usually this will be most easily generated with quote
env
The parent environment of the function, defaults to the calling environment of make_function
Aliases
  • fn_new
Examples
f <- function(x) x + 3
g <- fn_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))
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.