argumentDeparser: Pass 'arg = .(key1 = value1, key2 = value2)' function...

Description Usage Arguments Details Examples

View source: R/utilities.R

Description

argumentDeparser passes arg = .(key1 = value1, key2 = value2) function arguments to the appropriate function

Usage

1
2
3
4
5
6
argumentDeparser(
  arg,
  replace_dot,
  transform_logical = TRUE,
  null_params = NULL
)

Arguments

arg

an unevaluated call, see Details

replace_dot

a character string which defines the function to which arg should be passed to. If not provided, the name of arg is guessed using deparse and substitute, and "Params" is attached to call the corresponding parameter setter function.

transform_logical

logical; if TRUE (default), a single logical arg argument is treated in a special way (see Details)

null_params

a list of parameters which is passed to the parameter setter function (see 'replace_dot') if argumentDeparser would return NULL

Details

This function is not intended for direct use. It allows method = .(key = value) argument definition in high-level functions by substituting . to the appriopriate methodParams function. If transform_logical is TRUE, the call method = TRUE is transformed to method = methodParams(), thereby it returns the default parameter setting. Similarily, method = FALSE is treated as method = NULL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
mymethodParams <- function(x = 3, y = 4) {
    list(x = x, y = y)
}
tempfn <- function(mymethod = NULL, ...) {
    argumentDeparser(substitute(mymethod), "mymethodParams", ...)
}
stopifnot(is.null(tempfn()))
stopifnot(identical(tempfn(null_params = list(x = 1)),
                    list(x = 1, y = 4)))
stopifnot(identical(FALSE, 
                    tempfn(mymethod = FALSE, transform_logical = FALSE)))
stopifnot(identical(tempfn(mymethod = TRUE),
                    tempfn(mymethod = mymethodParams())))
new_y = 1:5
stopifnot(identical(tempfn(mymethod = .(y = new_y)),
                    tempfn(mymethod = mymethodParams(y = new_y))))

tdeenes/eegR documentation built on April 19, 2021, 4:17 p.m.