Learn R Programming

simsalapar (version 1.0-2)

grid-stuff: Tools For Working with Variable Specification Lists

Description

From a variable specification list (varlist), [object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

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 list of variable specifications, typically resulting from varlist(). Each variable spec is itself a named list which must contain a "value"
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 = instead of just .
n
for set.n.sim(): the value n.sim should be set to; an integer or NULL.

Value

  • For [object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

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)
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