get_dots | R Documentation |
...
arguments but with more features.Provides access to higher level call's arguments (including ...
dots arguments) without explicitly passing it through calling stack and allows updating default values that are explicitly set throughout calling stack (i.e., lower calls take prevalence).
get_dots(
function_or_arg_list = NULL,
select_args = NULL,
search_calls_with_formals = "...",
search_calls_of_env = NULL,
search_calls_regexp = NULL,
search_depth = 1L,
search_up_to_call = NULL,
skip_checks_for_parent_call = TRUE,
eval_default_args = FALSE,
return_unlisted_if_single_arg = TRUE
)
function_or_arg_list |
The end function that meant to accept dots arguments (default arguments accessed with |
select_args |
Which arguments to select from |
search_calls_with_formals |
Formals (parameters, arguments) that should be present in each upper call to continue looking up the call stack for updates in dots arguments. |
search_calls_of_env |
Environment/package name (character string) to which each function in upper calls to should belong to continue looking up the call stack for updates in dots arguments. |
search_calls_regexp |
Regular expression that each function name in upper calls to should matched to continue looking up the call stack for updates in dots arguments. |
search_depth |
Number of frames (aka environments) down in calling stack to look up arguments. |
search_up_to_call |
The name of the call before which to continue looking up the call stack for updates in dots arguments. |
skip_checks_for_parent_call |
Whether to skip checking |
eval_default_args |
Whether to evaluate default arguments. Default is do not evaluate (FALSE) assuming that all argument are simple values (i.e., evaluates to itself) |
return_unlisted_if_single_arg |
Toggle wether unlist when returning a single argument. Default is TRUE |
List of updated dots arguments
# Make get_dots available for following examples
get_dots <- nstandr:::get_dots
# Basic usage
util <- function(foo = 0, bar = 0) {
# get dots and bind updated arguments into environment
dots <- get_dots()
for (v in names(dots)) assign(v, dots[[v]])
# util just reports it arguments
message("foo: ", foo, ", bar: ", bar)
}
util()
#> foo: 0, bar: 0
main <- function (...) {
util()
util(foo = 1)
util(bar = 1)
}
main(foo = 2, bar = 2)
#> foo: 2, bar: 2
#> foo: 1, bar: 2 # THIS WORKS NOW!
#> foo: 2, bar: 1 # THIS WORKS NOW!
# Usage in nested calls
util <- function(foo = 0, bar = 0) {
# get dots and bind updated arguments into environment
dots <- get_dots(search_depth = 3L)
for (v in names(dots)) assign(v, dots[[v]])
# util just reports it arguments
message("foo: ", foo, ", bar: ", bar)
}
main <- function (...) {
util()
sub_main(foo = 1)
}
sub_main <- function (...) {
util()
sub_sub_main(bar = 2)
}
sub_sub_main <- function (...) {
util()
}
main()
#> foo: 0, bar: 0
#> foo: 1, bar: 0
#> foo: 0, bar: 2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.