where_to_get_args {matsindf}R Documentation

Decide where to get each argument to FUN

Description

The precedence rules for where to obtain values for the FUN argument to matsindf_apply() are codified here. The rules are:

Usage

where_to_get_args(.dat = NULL, FUN, ...)

Arguments

.dat

The .dat argument to matsindf_apply().

FUN

The FUN argument to matsindf_apply().

...

The ... argument to matsindf_apply().

Value

A named list wherein the names are the argument names to FUN. Values are character vectors with 2 elements. The first element is named source and provides the argument to matsindf_apply() from which the named argument should be found, one of ".dat", "FUN", or "...". The second element is named arg_name and provides the variable name or argument name in the source that contains the input data for the argument to FUN.

Examples

example_fun <- function(a = 1, b) {
  list(c = a + b, d = a - b)
}
# b is not available anywhere, likely causing an error later
matsindf:::where_to_get_args(FUN = example_fun)
# b is now available in ...
matsindf:::where_to_get_args(FUN = example_fun, b = 2)
# b is now available in .dat
matsindf:::where_to_get_args(list(b = 2), FUN = example_fun)
# b now comes from ..., because ... takes precedence over .dat
matsindf:::where_to_get_args(list(b = 2), FUN = example_fun, b = 3)
# Mapping from c in .dat to b in FUN
matsindf:::where_to_get_args(list(c = 2),
                             FUN = example_fun, b = "c")
# Redirect from an arg in ... to a different default to FUN
matsindf:::where_to_get_args(FUN = example_fun, b = "a")
# b is found in FUN, not in .dat, because the mapping (b = "a")
# is not available in .dat
matsindf:::where_to_get_args(list(b = 2), FUN = example_fun, b = "a")

[Package matsindf version 0.4.8 Index]