Skip to contents

arg(x) looks in the calling environment for the binding x, taken literally, and returns it as a quotation. arg(x) is equivalent to unwrap(quo(x)).

arg_ evaluates the first element normally; arg(x, e) is equivalent to arg_(quote(x), e).

arg_list looks up multiple variables, and returns a dots object. arg_list(x, y) is equivalent to unwrap(dots(x=x, y=y)). If any of the requested variables are not bound, an error will be raised.

arg_list_ is a normally evaluating version of arg_list; arg_list(x, y) is equivalent to arg_list_(alist(x, y), environment()).

set_arg and set_arg_ create bindings from quotations. They replace base function delayedAssign.

Usage

arg(sym, env = arg_env_(quote(sym), environment()))

arg_(sym, env = arg_env(sym, environment()))

arg_list(...)

arg_list_(syms, envs)

set_arg(dst, src)

set_arg_(dst, src)

Arguments

sym

The name to look up. For arg this is a literal name, not evaluated. For arg_ this should evaluate to a symbol or character.

env

The environment to look in. By default, the environment from which sym was passed.

...

Bare names (not forced). Arguments may be named; these names determine the names on the output list. If arguments are not named, the names given are used.

syms

A character vector or list of names.

envs

An environment, or a list of environments, to look for the bindings in.

dst

A name; for set_arg this is quoted literally; for set_arg_ this should be a quotation.

src

A quotation (or something that can be converted to a quotation, like a formula).

Value

arg returns a quotation object.

args returns a dots object.

arg_list returns a dots object.

Note

If you use a a literal character value, as in arg_("x", environment()), you MUST also give the environment parameter. The reason is that R will discard scope information about code literals in byte-compiled code; so when arg_("x") is called in compiled code, the default value for env will be found to be emptyenv().

Beware of writing arg_list(a, b, ...) which probably doesn't do what you want. This is because R unwraps ... before invoking arg_list, so this ends up double-unwrapping .... To capture ... alongside named arguments you can use the syntax arg_list(x, y, (...)) (which is equivalent to c(arg_list(x, y), dots(...))). You can also use get_call() to extract all function inputs to an active function.

See also

dots get_dots unwrap