Learn R Programming

simsalapar (version 1.0-12)

grid-stuff: Tools For Working with Variable Specification Lists

Description

From a variable specification list (varlist),

getEl()

gets elements of a variable specification list that match the given variable type.

mkGrid()

builds a grid, e.g., for parallel evaluation, basically by calling do.call(expand.grid, <list>).

mkNms()

builds a list of names, e.g., to be used as dimnames for a corresponding simulation result array.

get.n.sim()

extracts n.sim or returns 1 if it is not contained in vList.

set.n.sim()

modifies or sets n.sim in vList.

get.nonGrids()

extracts all variables not having type="grid" and returns n.sim the same as get.n.sim().

Usage

getEl       (vList, type = "ALL", comp = "value")
mkGrid      (vList)
mkNms       (vList, addNms = FALSE)
get.n.sim   (vList)
set.n.sim   (vList, n)
get.nonGrids(vList)

Value

For

getEl()

a named list containing the selected components of those variables that match the provided type.

mkGrid()

a data frame (data.frame).

mkNms()

a named list of the same length() and with the same names() as vList.

get.n.sim()

n.sim if it is contained in vList, 1 otherwise.

set.n.sim()

the varlist vList with a modified n.sim.

get.nonGrids()

list of length 2 containing the (possibly modified) n.sim and a list containing all variables not having type="grid".

Arguments

vList

a list of variable specifications, typically resulting from varlist(). Each variable spec is itself a named list which must contain a "value" component.

type

character vector of variable type or types to restrict the selection to. The default, "ALL" implies no restriction and hence returns all variables.

comp

either a character string containing the component name to pick out or NA (in which case all components are picked out).

addNms

logical, specifying if the resulting names should be of the form <var>=<value> instead of just <value>.

n

for set.n.sim(): the value n.sim should be set to; an integer or NULL.

Author

Marius Hofert and Martin Maechler.

Details

These functions are useful when working with variable specification lists.

See Also

varlist, for construction of variable lists. expand.grid, the “workhorse” of mkGrid().

Examples

Run this code
vList <-
 varlist(n.sim = list(type="N", expr = quote(N[sim]), value = 64),
         n     = list(type="grid",
                      value = c(20, 100, 500)), # sample sizes
         p     = list(type="grid",
                      value = c(3, 7, 15, 25)), # dimensions
         meth  = list(type="grid", expr = quote(italic(method)),
                      value = c("classical", "robust")))

getEl(vList, type="grid") # for those of type "grid", get all values
## for those of type "grid", get all components :
str(getEl(vList, type="grid", comp=NA))
stopifnot(identical(as(vList, "list"),
                    getEl(vList, type=c("N","grid"), comp = NA)))

(grd <- mkGrid(vList))
stopifnot(nrow(grd) == 3*4*2, ncol(grd) == 3)

getEl(vList)# -> all "value"s: the same as lapply(., `[[`, "value") :
stopifnot(identical(lapply(vList, `[[`, "value"),
                    getEl(vList)))
mkNms(vList)
mkNms(vList, addNms=TRUE)

get.n.sim(vl. <- set.n.sim(vList, NULL)) # 1
vl.$n.sim # NULL
set.n.sim(vl., 12)
# \dontshow{
stopifnot(is.null(vl.$n.sim),
	  identical(set.n.sim(vl., 12)$n.sim,
		    list(value = 12, type = "N", expr = quote(N[sim]))))
# }

Run the code above in your browser using DataLab