0

I have created parallel replicas of simmer simulation, same way like in introduction to simmer:

library(parallel)
library(simmer)

envs <- mclapply(1:100, function(i) {
  simmer("SuperDuperSim") %>%
    add_resource("nurse", 1) %>%
    add_resource("doctor", 2) %>%
    add_resource("administration", 1) %>%
    add_generator("patient", patient, function() rnorm(1, 10, 2)) %>%
    run(80) %>%
    wrap()
})

Now each object in envs is not a simmer class, but a wrap class instead. I want to modify some part of each envs object without modifying original object, but any change in the property will affect original object.

How can I clone wrap object to introduce some changes into it's properties and leave original object unchanged?

vkolesnik
  • 367
  • 2
  • 13

1 Answers1

1

Long research has shown that there is no explicit function which do exactly what I need for simmer objects. However, I have figured out that both simmer and wrap objects are of type environment. The obvious solution here is to clone the environment, which is answered here and assign same classes to newly created environment in order to make it looking like the original object.

Sample code:

clonedEnvs <- lapply(envs, function(env) {
  result <- as.environment(as.list.environment(env, all.names = TRUE))
  structure(result, class = class(env))
})
vkolesnik
  • 367
  • 2
  • 13