array-stuff {simsalapar} | R Documentation |
Tools For Converting To and From Arrays, Lists, and Array of Lists
Description
- ul()
is a simple wrapper for
unlist()
withrecursive=FALSE
.- mkAL()
gets a list
x
with elements that are named lists of length five, seex
below, and converts it to an array oflist
s.- saveSim()
(optionally) converts a result list to an array using
mkAL()
and (optionally) saves it to a file viasaveRDS()
.- maybeRead()
if the provided ‘.rds’ file exists, this function reads it via
readRDS()
; otherwise, nothing is done.- getArray()
gets an array of 4-
list
s as returned bymkAL()
, picks out the specified componentcomp
, applies the specified functionFUN
(with useful defaults), and builds anarray
.- array2df()
auxiliary function to convert an array to a
data.frame
(correctly dealing withn.sim
).
Usage
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")
Arguments
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 |
Details
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.
Value
For
- ul()
the unlisted list; see
unlist()
.- mkAL()
- saveSim()
the
array
returned bymkAL()
.- maybeRead()
the object read by
readRDS()
fromsfile
or nothing (ifsfile
does not exist).- getArray()
an
array
containing the values of the specified componentcomp
after applyingFUN
to them. The defaultFUN
produces anarray
, depending oncomp
, of- "value":
values or
err.value
(in case of an error)- "error":
logicals indicating whether there was an error
- "warning":
logicals indicating whether there was a warning
- "time":
timings as returned by
doCallWE()
, i.e., typically (frommkTimer
'sproc.time()[1]
) the number of milliseconds of “"CPU user time"”.
- array2df(x)
a
data.frame
with several columns built from thedimnames(x)
and a column namedresponseName
with the values ofx
.
Author(s)
Marius Hofert and Martin Maechler.
References
see simsalapar-package
.
See Also
getEl()
and mkNms()
used by
mkAL()
. saveRDS()
and
readRDS()
, the “workhorses” of
saveSim()
and maybeRead()
, respectively.
Examples
## 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)