is a simple wrapper for unlist()
with
recursive=FALSE
.
gets a list x
with elements that are named
lists of length five, see x
below, and converts it to an
array of list
s.
(optionally) converts a result list to an array using
mkAL()
and (optionally) saves it to a file via saveRDS()
.
if the provided .rds
file exists, this function
reads it via readRDS()
; otherwise, nothing is done.
gets an array of 4-list
s as returned
by mkAL()
, picks out the specified component comp
,
applies the specified function FUN
(with useful defaults),
and builds an array
.
auxiliary function to convert an array to a
data.frame
(correctly dealing with n.sim
).
ul(x)mkAL (x, vList, repFirst, check=TRUE)
saveSim(x, vList, repFirst, sfile, check=TRUE, doAL=TRUE)
maybeRead(sfile, msg=TRUE)
getArray(x, comp=c("value", "error", "warning", "time"),
FUN=NULL, err.value=NA)
array2df(x, responseName = "value")
For
the unlisted list; see unlist()
.
the array
returned by
mkAL()
.
the object read by readRDS()
from
sfile
or nothing (if sfile
does not exist).
an array
containing the values
of the specified component comp
after applying FUN
to them. The default FUN
produces an array
,
depending on comp
, of
values or err.value
(in case of an error)
logicals indicating whether there was an error
logicals indicating whether there was a warning
timings as returned by doCallWE()
,
i.e., typically (from mkTimer
's
proc.time()[1]
) the number of milliseconds
of “"CPU user time"”.
a data.frame
with several columns
built from the dimnames(x)
and a column named
responseName
with the values of x
.
for
a list.
a list (of length
n.sim * nrow(pGrid)
)
where each element is a list of length
five, containing the named elements "value"
,
"error"
, "warning"
, "time"
, and
".Random.seed"
, the first four as returned by
doCallWE()
.
an array of list
s as
returned by mkAL()
.
a numeric array as returned by
getArray(*, "value")
.
a list
of variable specifications. Each
variable specification is itself a named list which must contain a
"value"
component.
logical; must match the value of repFirst
in the x <- do*Apply()
call where x
has been created.
logical
activating consistency checks for
x
.
a file name, typically with extension .rds
or NULL
.
logical
indicating if mkAL()
should
be called, or rather just x
be saved.
logical
indicating whether a message is
printed when an object is read from sfile
.
numeric
which is used to replace the
value of the array entry in case of an error.
character string denoting the component.
function to be applied right before the resulting array
array
is constructed.
(for arrady2df()
:) a string specifying the
name of the “value” column of the resulting data frame.
Marius Hofert and Martin Maechler.
mkAL()
is useful when creating arrays from result
lists returned from large(r) simulation studies which use
doCallWE()
. To create a proper argument x
for
mkAL()
, the function ul()
turns out to
be useful to (stepwise) unlist nested lists.
getArray()
converts arrays of lists as returned by
mkAL()
to an array
of numeric
(or
logical
, see below) after applying the specified FUN
.
In case of an error, the corresponding entry in the resulting array is
replaced by err.value
.
The default FUN
converts possible errors and warnings to
logical
(indicating whether there was a error or
warning, respectively) and run times to numeric
. For
comp="value"
, the situation is trickier. First of all, the
resulting array contains dimensions for variables of type
“inner” and, if greater than 1, for the variable of type
“N” (typically called "n.sim"
); see the vignette for
details.
Use FUN = identity
to get at the full error or warning objects,
for comp = "error"
or for comp = "warning"
, respectively.
saveSim()
and maybeRead()
are
useful for creating and (re)storing arrays from large(r) simulation
studies (to avoid recomputation, to ease the data analysis etc.).
saveSim()
calls mkAL()
, nowadays wrapped in
tryCatch(.)
, such that the simulation is not lost, even
when the resulting format cannot correctly be treated by
mkAL()
. Consequently, doAL
is not much needed anymore.
Note that both saveSim()
and maybeRead()
accept
sfile=NULL
in which case nothing is saved or read.
see simsalapar-package
.
if (FALSE) {
## Get at the full error objects, notably (message, call):
errObjs <- getArray(res, "error", FUN=identity)
}
if(FALSE) ## A longer, "interesting" example is in
demo(robust.mean)
Run the code above in your browser using DataLab