fn_fmls() returns a named list of formal arguments. fn_fmls_names() returns the names of the arguments. fn_fmls_syms() returns formals as a named list of symbols. This is especially useful for forwarding arguments in constructed calls.

fn_fmls(fn = caller_fn())

fn_fmls_names(fn = caller_fn())

fn_fmls_syms(fn = caller_fn())

Arguments

fn

A function. It is lookep up in the calling frame if not supplied.

Details

Unlike formals(), these helpers also work with primitive functions. See is_function() for a discussion of primitive and closure functions.

See also

lang_args() and lang_args_names()

Examples

# Extract from current call: fn <- function(a = 1, b = 2) fn_fmls() fn()
#> $a #> [1] 1 #> #> $b #> [1] 2 #>
# Works with primitive functions: fn_fmls(base::switch)
#> $EXPR #> #> #> $... #> #>
# fn_fmls_syms() makes it easy to forward arguments: lang("apply", !!! fn_fmls_syms(lapply))
#> apply(X = X, FUN = FUN, ...)