Learn R Programming

simsalapar (version 1.0-2)

doCallWE: Innermost Computation: Error Catching Version of do.call()

Description

doCallWE() performs the innermost computation of the simulation study at hand. It is a version of do.call(f, argl, *), with care of catching and storing both error and warnings (via tryCatch.W.E()) and measures user time. This is useful in large(r) simulation studies.

mkTimer() returns a function to be passed as timer to doCallWE().

Usage

doCallWE(f, argl,         timer = mkTimer(gcFirst=FALSE))

mkTimer(gcFirst)

Arguments

f
a function which given data and parameters, computes the statistic we are simulating.
argl
list of arguments for f().
timer
a function similar to system.time(); by default, measure user time in milliseconds.
gcFirst
logical, passed to system.time(), as it is called from the resulting function mkTimer().

Value

  • doCallWE() returns a list with components
  • valuef$(\langle \mathtt{argl} \rangle)$, if there was no error, or NULL otherwise.
  • errorerror message (see simpleError or stop()) or NULL.
  • warningwarning message (see simpleWarning or warning()) or NULL.
  • timetime, as measured by timer().

Details

Note that gcFirst=FALSE is default for a good reason: if a call to doOne() is relatively fast, calling gc() every time is unnecessarily expensive and may completely dominate the overall simulation run time. gcFirst=TRUE is preferable otherwise, as it ensures less variable timings, see system.time.

See Also

do.call, tryCatch.W.E.

Examples

Run this code
set.seed(61)
L <- log(abs(rt(n=100, df = 1.5)))
r <- doCallWE(quantile, list(L, probs= 0.95))
## set timer for  "no timing" :
u <- doCallWE(quantile, list(L, probs= 0.95), timer = function(E) { E; NULL })
stopifnot(is.null(r$error),
	  all.equal(r$value, quantile(L, 0.95)),
	  identical(r[1:3], u[1:3]), is.null(u[["time"]]))

Run the code above in your browser using DataLab