Link Search Menu Expand Document
set_config {SimEngine}R Documentation

Modify the simulation configuration


This function sets configuration options for the simulation. If the 'packages' argument is specified, all packages will be loaded and attached via library when set_config is called. Multiple calls to set_config will only overwrite configuration options that are specified in the subsequent calls, leaving others in place. You can see the current configuration via print(sim), where sim is your simulation object.


  num_sim = 1000,
  parallel = "none",
  n_cores = parallel::detectCores() - 1,
  packages = NULL,
  stop_at_error = FALSE,
  progress_bar = TRUE,
  seed = NA



A simulation object of class sim_obj, usually created by new_sim


An integer; the number of simulations to conduct for each level combination


A string; one of c("outer", "inner", "none"). Controls which sections of the code are parallelized. Setting to "outer" will run one simulation per core. Setting to "inner" will allow for parallelization within a single simulation replicate. Setting to "none" will not parallelize any code. See for an overview of how parallelization works in SimEngine. This option will be ignored if the simulation is being run on a cluster computing system.


An integer; determines the number of CPUs on which the simulation will run if using parallelization. Defaults to one fewer than the number of available CPUs on the current host.


A character vector of packages to load and attach


A Boolean. If set to TRUE, the simulation will stop if it encounters an error in any single replicate Useful for debugging.


A Boolean. If set to FALSE, the progress bar that is normally displayed while the simulation is running is suppressed.


An integer; seeds allow for reproducible simulation results. If a seed is specified, then consecutive runs of the same simulation with the same seed will lead to identical results (under normal circumstances). If a seed was not set in advance by the user, SimEngine will set a random seed, which can later be retrieved using the vars function. See details for further info.


  • If a user specifies, for example, set_config(seed=4), this seed is used twice by SimEngine. First, SimEngine executes set.seed(4) at the end of the set_config call. Second, this seed is used to generate a new set of seeds, one for each simulation replicate. Each of these seeds is set in turn (or in parallel) when run is called.

  • Even if seeds are used, not all code will be reproducible. For example, a simulation that involves getting the current date/time with Sys.time() or dynamically retrieving external data may produce different results on different runs.


The original simulation object with a modified configuration


sim <- new_sim()
sim %<>% set_config(
  num_sim = 10,
  seed = 2112

[Package SimEngine version 1.1.0 ]