Inspect an argument

arg_inspect() provides argument introspection in the context of lazy evaluation. Compared to tidy_capture(), the returned information is more complete and takes R's lazy evaluation semantics into account: if an argument is passed around without being evaluated, arg_inspect() is able to return the expression at the original call site as well as the relevant scoping environment in which this expression is supposed to be evaluated when the argument is forced. To accomplish this, arg_inspect() climbs the call stack to find where an argument was first supplied, with which expression, in which evaluation environment. arg_inspect_() is the standard-evaluation version of arg_inspect() and takes a symbol and a call stack object.

arg_inspect_(expr, stack, only_dots = FALSE)
An argument to a function.
A quoted symbol giving the name of the argument to inspect.
A call_stack object as returned by call_stack().
Whether to stop introspection once forwarded dots have been climbed. Setting this to TRUE is only useful for inspecting dots (cf. tidy_dots() which does not follow symbols).

arg_inspect() should be used with two caveats in mind. First, it is slower than tidy_capture() and lazyeval::lazy(). Thus you should probably avoid using it in functions that might be used in tight loops (such as a loop over the rows of data frame). Second, arg_inspect() ignores all reassignment of arguments. It has no way of detecting that an inspected argument got reassigned along the way, and will continue to climb the calls looking for an earlier call site. These two limitations are inherent to the stack climbing approach that powers this function.


A list containing:

  • arg_inspect
  • arg_inspect_
Documentation reproduced from package rlang, version, License: GPL-3

Community examples

Looks like there are no examples yet.