View source: R/summary_utility_functions.R
| filter_call_args | R Documentation |
Simplifies the common pattern of filtering arguments from a source list to match a target function's formal parameters, then adding/overriding specific arguments.
filter_call_args(source_args, target_func, override_args = NULL)
source_args |
List of all arguments (typically from |
target_func |
Function whose formals define the filter criteria. |
override_args |
List of arguments to add or override (optional). |
This function:
Extracts formal parameter names from target_func
Keeps only arguments from source_args that match those names
Adds or overrides with any override_args provided
Reduces boilerplate and improves readability across the codebase.
List of filtered arguments ready for do.call().
## Not run:
# Instead of:
args_FS <- names(formals(get_FSdata))
args_FS_filtered <- args_call_all[names(args_call_all) %in% args_FS]
args_FS_filtered$df.analysis <- df.analysis
args_FS_filtered$grf_cuts <- grf_cuts
FSdata <- do.call(get_FSdata, args_FS_filtered)
# You now write:
FSdata <- do.call(get_FSdata,
filter_call_args(args_call_all, get_FSdata,
list(df.analysis = df.analysis, grf_cuts = grf_cuts)))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.