Skip to contents

Update function default parameters

Usage

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

Arguments

function_name

character function name, passed to formals()

param_name

character string of one parameter / argument name.

new_values

any relevant R object type to use for the function parameter / argument.

verbose

logical whether to print verbose output

...

additional arguments are ignored.

Value

a list with class matching the R function argument.

Details

This function is a minor extension to update_list_elements() intended to help update function parameters which are defined as a nested list. It will update internal components of the nested list without replacing the whole list.

It is very similar to modifyList() except for a nested list.

Examples

params1 <- list(
   jammanorm=list(
      controlGenes=c("HK1", "HK2")
   ),
   cyclicLoess=list(method="affy"),
   quantile=list(ties=FALSE)
)

# 1. Not correct: update arguments with modifyList()
fn_defaults <- eval(formals("matrix_normalize"))
new_fn_args <- modifyList(fn_defaults, list(params=params1))
str(new_fn_args$params)
#> List of 3
#>  $ jammanorm  :List of 1
#>   ..$ controlGenes: chr [1:2] "HK1" "HK2"
#>  $ cyclicLoess:List of 1
#>   ..$ method: chr "affy"
#>  $ quantile   :List of 1
#>   ..$ ties: logi FALSE
str(new_fn_args$params$jammanorm)
#> List of 1
#>  $ controlGenes: chr [1:2] "HK1" "HK2"

# 2. update only params argument with modifyList()
new_fn_params <- modifyList(eval(fn_defaults$params), params1)
str(new_fn_params)
#> List of 6
#>  $ cyclicLoess       :List of 5
#>   ..$ weights      : NULL
#>   ..$ span         : num 0.7
#>   ..$ adaptive.span: logi FALSE
#>   ..$ iterations   : num 3
#>   ..$ method       : chr "affy"
#>  $ quantile          :List of 1
#>   ..$ ties: logi FALSE
#>  $ jammanorm         :List of 8
#>   ..$ controlGenes     : chr [1:2] "HK1" "HK2"
#>   ..$ minimum_mean     : num 0
#>   ..$ maximum_mean     : num Inf
#>   ..$ controlSamples   : NULL
#>   ..$ centerGroups     : NULL
#>   ..$ useMedian        : logi FALSE
#>   ..$ noise_floor      : NULL
#>   ..$ noise_floor_value: NULL
#>  $ limma_batch_adjust:List of 2
#>   ..$ batch: NULL
#>   ..$ group: NULL
#>  $ TMM               :List of 5
#>   ..$ refColumn   : NULL
#>   ..$ logratioTrim: num 0.3
#>   ..$ sumTrim     : num 0.05
#>   ..$ doWeighting : logi TRUE
#>   ..$ Acutoff     : NULL
#>  $ TMMwsp            :List of 5
#>   ..$ refColumn   : NULL
#>   ..$ logratioTrim: num 0.3
#>   ..$ sumTrim     : num 0.05
#>   ..$ doWeighting : logi TRUE
#>   ..$ Acutoff     : NULL
str(new_fn_params$jammanorm)
#> List of 8
#>  $ controlGenes     : chr [1:2] "HK1" "HK2"
#>  $ minimum_mean     : num 0
#>  $ maximum_mean     : num Inf
#>  $ controlSamples   : NULL
#>  $ centerGroups     : NULL
#>  $ useMedian        : logi FALSE
#>  $ noise_floor      : NULL
#>  $ noise_floor_value: NULL

# 3. use update_function_params()
params2 <- update_function_params(
   function_name="matrix_normalize",
   param_name="params",
   new_values=params1)
str(params2)
#> List of 6
#>  $ cyclicLoess       :List of 5
#>   ..$ weights      : NULL
#>   ..$ span         : num 0.7
#>   ..$ adaptive.span: logi FALSE
#>   ..$ iterations   : num 3
#>   ..$ method       : chr "affy"
#>  $ quantile          :List of 1
#>   ..$ ties: logi FALSE
#>  $ jammanorm         :List of 8
#>   ..$ controlGenes     : chr [1:2] "HK1" "HK2"
#>   ..$ minimum_mean     : num 0
#>   ..$ maximum_mean     : num Inf
#>   ..$ controlSamples   : NULL
#>   ..$ centerGroups     : NULL
#>   ..$ useMedian        : logi FALSE
#>   ..$ noise_floor      : NULL
#>   ..$ noise_floor_value: NULL
#>  $ limma_batch_adjust:List of 2
#>   ..$ batch: NULL
#>   ..$ group: NULL
#>  $ TMM               :List of 5
#>   ..$ refColumn   : NULL
#>   ..$ logratioTrim: num 0.3
#>   ..$ sumTrim     : num 0.05
#>   ..$ doWeighting : logi TRUE
#>   ..$ Acutoff     : NULL
#>  $ TMMwsp            :List of 5
#>   ..$ refColumn   : NULL
#>   ..$ logratioTrim: num 0.3
#>   ..$ sumTrim     : num 0.05
#>   ..$ doWeighting : logi TRUE
#>   ..$ Acutoff     : NULL
str(params2$jammanorm)
#> List of 8
#>  $ controlGenes     : chr [1:2] "HK1" "HK2"
#>  $ minimum_mean     : num 0
#>  $ maximum_mean     : num Inf
#>  $ controlSamples   : NULL
#>  $ centerGroups     : NULL
#>  $ useMedian        : logi FALSE
#>  $ noise_floor      : NULL
#>  $ noise_floor_value: NULL