REUSABLE DISCRETE-EVENT SIMULATION IN R: QUOSURE-BASED ENCAPSULATION OF SIMMER MODELS FOR SHINY REACTIVITY AND PARALLEL PROBABILISTIC SENSITIVITY ANALYSIS

Author(s)

Richard F. Pollock, MA, MSc;
Covalence Research Ltd, Director, Harpenden, United Kingdom
OBJECTIVES: Discrete-event simulation (DES) models built in R using simmer are often required in two distinct execution contexts: interactive Shiny applications, where the model may be evaluated once per reactive interface update, and probabilistic sensitivity analysis (PSA), requiring large numbers of independent replications, ideally in parallel. Maintaining a single source-of-truth model while ensuring isolation of run-specific inputs and reproducible random number generation across contexts is non-trivial. We present a method using R quosures to enable safe reuse of the same simmer model for Shiny and parallel PSA using the mirai package.
METHODS: The DES is defined once in a quosure using quo(). For PSA iterations, the quosure environment can be set with quo_set_env() to a child_env() that contains all model parameters and a replication-specific random number generator (RNG) seed, and then run using eval_tidy() within mirai::mirai_map(). Parameter draws and seeds are generated per replication and passed to mirai_map; each worker constructs its own child environment and evaluates the same quosure, ensuring isolation and eliminating dependence on implicit global random number generator state or scheduling. In Shiny, the quosure can be wrapped with shiny::reactive() and then evaluated using inject() resulting in evaluation once per reactive update and avoiding mutation of global state.
RESULTS: The quosure pattern supports reuse of an identical simmer model across interactive and parallel execution contexts; Shiny outputs are recomputed deterministically and isolated from the global scope. PSA replications execute independently and in parallel, with correct scoping of run-specific variables and deterministic outputs when re-run, including under different worker counts and execution orders. The approach reduced code duplication and simplified maintenance by separating model definition from execution context.
CONCLUSIONS: Quosure encapsulation with per-run child environments including explicit RNG seeds provides a lightweight, reproducible method to reuse simmer DES code across Shiny and parallel PSA with mirai, mitigating common scoping and reproducibility pitfalls.

Conference/Value in Health Info

2026-05, ISPOR 2026, Philadelphia, PA, USA

Value in Health, Volume 29, Issue S6

Code

MSR141

Topic

Methodological & Statistical Research

Disease

No Additional Disease & Conditions/Specialized Treatment Areas

Your browser is out-of-date

ISPOR recommends that you update your browser for more security, speed and the best experience on ispor.org. Update my browser now

×