sim {saeSim} | R Documentation |
Start simulation
Description
This function will start the simulation. Use the printing method as long as you are testing the scenario.
Usage
sim(
x,
R = 1,
path = NULL,
overwrite = TRUE,
...,
suffix = NULL,
fileExt = ".csv",
libs = NULL,
exports = NULL
)
Arguments
x |
a |
R |
number of repetitions. |
path |
optional path in which the simulation results can be saved. They
will we coerced to a |
overwrite |
|
... |
arguments passed to |
suffix |
an optional suffix of file names. |
fileExt |
the file extension. Default is ".csv" - alternative it can be ".RData". |
libs |
arguments passed to |
exports |
arguments passed to |
Details
The package parallelMap is utilized as back-end for parallel computations.
Use the argument path
to store the simulation results in a directory.
This may be a good idea for long running simulations and for those using
large data.frame
s. You can use sim_read_data
to read
them in. The return value will change to NULL in each run.
Value
The return value is a list. The elements are the results of each
simulation run, typically of class data.frame
. In case you specified
path
, each element is NULL
.
Examples
setup <- sim_base_lm()
resultList <- sim(setup, R = 1)
# For parallel computations you may need to export objects
localFun <- function() cat("Hello World!")
comp_fun <- function(dat) {
localFun()
dat
}
res <- sim_base_lm() %>%
sim_comp_pop(comp_fun) %>%
sim(R = 2,
mode = "socket", cpus = 2,
exports = "localFun")
str(res)