Filter and merge arguments for function calls
Source:R/summary_utility_functions.R
filter_call_args.RdSimplifies the common pattern of filtering arguments from a source list to match a target function's formal parameters, then adding/overriding specific arguments.
Arguments
- source_args
List of all arguments (typically from
mget()or a stored args list).- target_func
Function whose formals define the filter criteria.
- override_args
List of arguments to add or override (optional).
Value
List of filtered arguments ready for do.call().
Details
This function:
Extracts formal parameter names from
target_funcKeeps only arguments from
source_argsthat match those namesAdds or overrides with any
override_argsprovided
Reduces boilerplate and improves readability across the codebase.
Examples
if (FALSE) { # \dontrun{
# 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)))
} # }