Learn R Programming

saeSim (version 0.11.0)

sim: 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 sim_setup

R

number of repetitions.

path

optional path in which the simulation results can be saved. They will we coerced to a data.frame and then saved as 'csv'.

overwrite

TRUE/FALSE. If TRUE files in path are replaced. If FALSE files in path are not replaced and simulation will not be recomputed.

...

arguments passed to parallelStart.

suffix

an optional suffix of file names.

fileExt

the file extension. Default is ".csv" - alternative it can be ".RData".

libs

arguments passed to parallelLibrary. Will be used in a call to do.call after coersion with as.list.

exports

arguments passed to parallelExport. Will be used in a call to do.call after coersion with as.list.

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.

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.frames. You can use sim_read_data to read them in. The return value will change to NULL in each run.

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab