Update function default parameters

update_function_params(
  function_name = NULL,
  param_name = NULL,
  new_values = NULL,
  verbose = FALSE,
  ...
)

Arguments

function_name

function or character string referring to the name of a function, passed to formals().

param_name

character string of the argument/parameter name in formals() of the function_name.

new_values

list or named vector used to update or augment existing default argument values defined for param_name of formals() of function_name.

verbose

logical indicating whether to print verbose output.

...

additional arguments are ignored.

Details

This function is a minor extension to update_list_elements() intended to help update function parameters which are defined as a nested list. See examples.

The main utility is for a function that defines a full set of required argument values, where the user calling the function may want to modify onyl a subset of those default values.

Examples

# function uses y as passed to the function
test_function_1 <- function(y=list(a=1, b=4)) {
   print("y:");
   print(y);
}
test_function_1(y=list(b=5, d=1:5))
#> [1] "y:"
#> $b
#> [1] 5
#> 
#> $d
#> [1] 1 2 3 4 5
#> 

# function starts with y formals, adds or updates new values
test_function_2 <- function(y=list(a=1, b=4)) {
   y <- update_function_params(test_function_1,
      param_name="y",
      new_values=y);
   print("y:");
   print(y);
}
test_function_2(y=list(b=5:6, d=1:5))
#> [1] "y:"
#> $a
#> [1] 1
#> 
#> $b
#> [1] 5 6
#> 
#> $d
#> [1] 1 2 3 4 5
#>