| grid-stuff {simsalapar} | R Documentation |
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
listof names, e.g., to be used asdimnamesfor a corresponding simulation resultarray.- get.n.sim()
extracts
n.simor returns 1 if it is not contained invList.- set.n.sim()
modifies or sets
n.siminvList.- get.nonGrids()
extracts all variables not having
type="grid"and returnsn.simthe same asget.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)
Arguments
vList |
a |
type |
|
comp |
either a |
addNms |
logical, specifying if the resulting names should be of
the form |
n |
for |
Details
These functions are useful when working with variable specification lists.
Value
For
- getEl()
a named
listcontaining the selected components of those variables that match the providedtype.- mkGrid()
a data frame (
data.frame).- mkNms()
a named
listof the samelength()and with the samenames()asvList.- get.n.sim()
n.simif it is contained invList, 1 otherwise.- set.n.sim()
the
varlistvListwith a modifiedn.sim.- get.nonGrids()
listof length 2 containing the (possibly modified)n.simand alistcontaining all variables not havingtype="grid".
Author(s)
Marius Hofert and Martin Maechler.
See Also
varlist, for construction of variable lists.
expand.grid, the “workhorse” of mkGrid().
Examples
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)