fn_fmls

0th

Percentile

Extract arguments from a function

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.

Usage
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()

Aliases
  • fn_fmls
  • fn_fmls_names
  • fn_fmls_syms
Examples
# NOT RUN {
# Extract from current call:
fn <- function(a = 1, b = 2) fn_fmls()
fn()

# Works with primitive functions:
fn_fmls(base::switch)

# fn_fmls_syms() makes it easy to forward arguments:
lang("apply", !!! fn_fmls_syms(lapply))
# }
Documentation reproduced from package rlang, version 0.1.6, License: GPL-3

Community examples

Looks like there are no examples yet.