Skip to contents

Evaluates a simulation function on each row of a data frame or tibble containing parameter values. Returns a single tibble with parameters and simulation results. The function uses furrr::future_pmap, which allows for easy parallelization.

Usage

evaluate_by_row(
  params,
  sim_function,
  ...,
  results_name = ".results",
  .progress = FALSE,
  .options = furrr::furrr_options(),
  system_time = TRUE
)

Arguments

params

data frame or tibble containing simulation parameter values. Each row should represent a separate set of parameter values.

sim_function

function to be evaluated, with argument names matching the variable names in params. The function must return a data.frame, tibble, or vector.

...

additional arguments passed to sim_function.

results_name

character string to set the name of the column storing the results of the simulation. Default is ".results".

.progress

A single logical. Should a progress bar be displayed? Only works with multisession, multicore, and multiprocess futures. Note that if a multicore/multisession future falls back to sequential, then a progress bar will not be displayed.

Warning: The .progress argument will be deprecated and removed in a future version of furrr in favor of using the more robust progressr package.

.options

The future specific options to use with the workers. This must be the result from a call to furrr_options().

system_time

logical indicating whether to print computation time. TRUE by default.

Value

A tibble containing parameter values and simulation results.

Examples

df <- data.frame(
  n = 3:5,
  lambda = seq(8, 16, 4)
)

evaluate_by_row(df, rpois)
#> Warning: UNRELIABLE VALUE: Future (‘<none>’) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".
#>    user  system elapsed 
#>   0.075   0.003   0.084 
#> # A tibble: 12 × 3
#>        n lambda .results
#>    <int>  <dbl>    <int>
#>  1     3      8        9
#>  2     3      8       12
#>  3     3      8        6
#>  4     4     12       13
#>  5     4     12        8
#>  6     4     12       11
#>  7     4     12        9
#>  8     5     16       10
#>  9     5     16       19
#> 10     5     16       15
#> 11     5     16       15
#> 12     5     16        8