parSim_dt: Parallel Simulator data.table version

View source: R/parSim_dt.R

parSim_dtR Documentation

Parallel Simulator data.table version

Description

The function uses the more efficient data.table in its internal code instead of dplyr, thereby speeding up the function itself and also allowing researchers to use data.table to speed up the code they want to simulate with parSim.

Usage

parSim_dt(
    ...,
    expression,
    replications = 1,
    reps,
    write = FALSE,
    name,
    nCores = 1,
    export = NULL,
    packages = NULL,
    exclude,
    debug = FALSE,
    progress = TRUE,
    progressbar,
    env = parent.frame(),
    seed = NULL
)

Arguments

...

Any number of R vectors representing the simulation conditions.

expression

An R expression that uses the simulation conditions as variable names. The expression must return a named list or a data.frame. Row names of returned data frames are dropped; put identifiers in a proper column if needed.

replications

Integer. The number of replications for each condition. Defaults to 1.

reps

Deprecated. Alias for replications, kept for backward compatibility; if supplied it overrides replications and a deprecation warning is issued.

write

Logical, should the results be written to a file? If TRUE, the results are written to paste0(name, ".txt") when name is provided, or to a temporary file (via tempfile) otherwise, and the path is reported with a message. Unlike previous versions, the results are also returned (invisibly) rather than NULL. Defaults to FALSE.

name

Name of the file if write = TRUE. A .txt extension is appended automatically. If omitted, a temporary file is used.

nCores

An integer value indicating the number of cores to use for parallel execution. Defaults to 1.

packages

A character vector containing the names of packages to be loaded on the parallel backend (only relevant when nCores > 1). Defaults to NULL.

export

A character vector of global objects to export to the cluster. Defaults to NULL (nothing exported).

exclude

A character vector of logical expressions indicating simulation conditions to exclude. The expressions are combined with | (OR) and evaluated in the context of the simulation design: any row matching at least one expression is removed.

debug

Logical. If TRUE, prints iteration details during execution. Only useful when running sequentially (nCores = 1); in parallel runs the output goes to the worker consoles and is not visible. Defaults to FALSE.

progress

Logical. If TRUE, shows a progress bar while running the simulation. Defaults to TRUE.

progressbar

Deprecated. Alias for progress, kept for backward compatibility; if supplied (and progress is not) it sets progress and a deprecation warning is issued.

seed

Optional integer. When supplied, one L'Ecuyer-CMRG random-number substream is derived per simulation condition (per design row), making the results fully reproducible and identical for any value of nCores. The caller's RNG state is restored afterwards. Defaults to NULL (no seeding).

env

The environment from which to export variables specified in the export argument, and in which unresolved symbols of expression and exclude are looked up when running sequentially. Defaults to parent.frame() (i.e., the caller's environment). export/env behave identically for sequential (nCores = 1) and parallel runs.

Details

The function uses data.table in its internal code instead of dplyr, thereby speeding up the simulation and allowing researchers to use data.table in the code they want to simulate with parSim.

Value

A data.table with the results of each iteration in each row, sorted by the id column (the row number of the condition in the fully expanded design). Besides the simulation conditions, the replication number and the columns returned by expression, the output contains: id (integer identifying the design row), error (logical; TRUE if the expression threw an error) and message (the error message, NA on success). Check any(output$error) after a run. When write = TRUE the results are also written to a file and returned invisibly.

Author(s)

Xinkai Du <xinkai.du.xd@gmail.com>

See Also

parSim


parSim documentation built on July 17, 2026, 1:07 a.m.