substitute_call: Substitute Values from an Environment into a Call

View source: R/operations.R

substitute_callR Documentation

Substitute Values from an Environment into a Call

Description

Substitute Values from an Environment into a Call

Usage

substitute_call(sub_call, envir, more_subs = list(), depth = 1, quote = TRUE)

Arguments

sub_call

R expression, quoted if quote = FALSE, unquoted otherwise. May also be a symbol or constant.

envir

An environment from which to substitute values.

more_subs

Optional named list of additional values to substitute. If any names are shared with envir, those in more_subs take precedence.

depth

Used internally to track recursion depth. Do not specify this argument.

quote

Logical. Should the call be quoted (i.e., it is passed as an unevaluated expression?).

Details

This function recursively traverses an R call object (a list-like representation of the abstract syntax tree) and replaces names with corresponding values in envir. Mandatory non-default arguments to any function in the call are substituted the same way, even if omitted; thus, this function can convert semantically invalid calls into valid ones. The modified call may still be invalid, however, if some mandatory arguments are unspecified and neither envir or more_subs contains substitutions for them.

This function is meant to be used with calls to functions from this package, using a LinRegProblem instance as envir. Because most function arguments are also attributes of LinRegProblem objects, doing so will automatically yield a valid call.

Value

Call object with all matched names substituted with corresponding names.


ryan-heslin/RegLesson documentation built on Aug. 5, 2022, 9:03 p.m.