array-stuff | R Documentation |
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")
x |
for
|
vList |
a |
repFirst |
logical; must match the value of |
check |
|
sfile |
a file name, typically with extension ‘.rds’ or |
doAL |
|
msg |
|
err.value |
|
comp |
character string denoting the component. |
FUN |
function to be applied right before the resulting array
|
responseName |
(for |
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.
For
the unlisted list; see unlist()
.
an array
of list
s.
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
.
Marius Hofert and Martin Maechler.
see simsalapar-package
.
getEl()
and mkNms()
used by
mkAL()
. saveRDS()
and
readRDS()
, the “workhorses” of
saveSim()
and maybeRead()
, respectively.
## Not run:
## Get at the full error objects, notably (message, call):
errObjs <- getArray(res, "error", FUN=identity)
## End(Not run)
if(FALSE) ## A longer, "interesting" example is in
demo(robust.mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.