Extract from a vector of character strings the names of special functions and auxiliary arguments

parseSpecialNames(x, special, arguments)

Arguments

x

Vector of character strings.

special

A character string: the name of the special argument.

arguments

A vector which contains the arguments of the special function

Value

A named list of parsed arguments. The names of the list are the special variable names, the elements are lists of arguments.

Details

Signals an error if an element has more arguments than specified by argument arguments.

See also

model.design

Author

Thomas A. Gerds <tag@biostat.ku.dk>

Examples


## ignore arguments
parseSpecialNames("treat(Z)",special="treat")
#> $Z
#> NULL
#> 
## set default to 0
parseSpecialNames(c("log(Z)","a","log(B)"),special="log",arguments=list("base"=0))
#> $Z
#> $Z$base
#> [1] 0
#> 
#> 
#> $B
#> $B$base
#> [1] 0
#> 
#> 
## set default to 0
parseSpecialNames(c("log(Z,3)","a","log(B,base=1)"),special="log",arguments=list("base"=0))
#> $Z
#> $Z$base
#> [1] "3"
#> 
#> 
#> $B
#> $B$base
#> [1] "1"
#> 
#> 
## different combinations of order and names
parseSpecialNames(c("log(Z,3)","a","log(B,1)"),
                  special="log",
                  arguments=list("base"=0))
#> $Z
#> $Z$base
#> [1] "3"
#> 
#> 
#> $B
#> $B$base
#> [1] "1"
#> 
#> 
parseSpecialNames(c("log(Z,1,3)","a","log(B,u=3)"),
                  special="log",
                  arguments=list("base"=0,"u"=1))
#> $Z
#> $Z$base
#> [1] "1"
#> 
#> $Z$u
#> [1] "3"
#> 
#> 
#> $B
#> $B$base
#> [1] 0
#> 
#> $B$u
#> [1] "3"
#> 
#> 
parseSpecialNames(c("log(Z,u=1,base=3)","a","log(B,u=3)"),
                  special="log",
                  arguments=list("base"=0,"u"=1))
#> $Z
#> $Z$base
#> [1] "3"
#> 
#> $Z$u
#> [1] "1"
#> 
#> 
#> $B
#> $B$base
#> [1] 0
#> 
#> $B$u
#> [1] "3"
#> 
#> 
parseSpecialNames(c("log(Z,u=1,base=3)","a","log(B,base=8,u=3)"),
                  special="log",
                  arguments=list("base"=0,"u"=1))
#> $Z
#> $Z$base
#> [1] "3"
#> 
#> $Z$u
#> [1] "1"
#> 
#> 
#> $B
#> $B$base
#> [1] "8"
#> 
#> $B$u
#> [1] "3"
#> 
#> 
parseSpecialNames("treat(Z,u=2)",
                  special="treat",
                  arguments=list("u"=1,"k"=1))
#> $Z
#> $Z$u
#> [1] "2"
#> 
#> $Z$k
#> [1] 1
#> 
#> 
parseSpecialNames(c("treat(Z,1,u=2)","treat(B,u=2,k=3)"),
                  special="treat",
                  arguments=list("u"=NA,"k"=NULL))
#> $Z
#> $Z$u
#> [1] "2"
#> 
#> $Z$k
#> [1] "1"
#> 
#> 
#> $B
#> $B$u
#> [1] "2"
#> 
#> $B$k
#> [1] "3"
#> 
#> 
## does not work to set default to NULL:
parseSpecialNames(c("treat(Z,1,u=2)","treat(B,u=2)"),
                  special="treat",
                  arguments=list("u"=NA,"k"=NULL))
#> $Z
#> $Z$u
#> [1] "2"
#> 
#> $Z$k
#> [1] "1"
#> 
#> 
#> $B
#> $B$u
#> [1] "2"
#> 
#> $B$k
#> [1] NA
#> 
#>