Objects in epiworldR (models, tools, viruses) are pointers to C++
objects, so the assignment operator (<-) only copies the pointer:
changing the "copy" changes the original. clone_epi() creates an
independent copy of the underlying C++ object instead.
Usage
clone_epi(x, ...)
# S3 method for class 'epiworld_tool'
clone_epi(x, ...)
# S3 method for class 'epiworld_virus'
clone_epi(x, ...)
# S3 method for class 'epiworld_model'
clone_epi(x, ...)Details
Copies of tools and viruses keep their type and all of their settings
(e.g., names, probabilities, distribution functions, and targets). For
example, cloning the vaccine of a measles model (retrieved with
get_tool()) gives another all-or-nothing vaccine, which the generic
tool() cannot create.
Copies of tools and viruses are new objects: once added to a model with
add_tool() or add_virus(), they get their own id (and, for viruses,
their own lineage), so the model records them separately from the
original. Use set_name_tool() or set_name_virus() to tell them apart
in the outputs.
clone_epi() replaces clone_model(), which is deprecated.
Examples
model <- ModelSIRCONN(
name = "COVID-19", n = 1000, prevalence = 0.01, contact_rate = 5,
transmission_rate = 0.4, recovery_rate = 0.95
)
vax <- tool(
name = "Vaccine", prevalence = 0.5, as_proportion = TRUE,
susceptibility_reduction = 0.9, transmission_reduction = 0.5,
recovery_enhancer = 0.5, death_reduction = 0.9
)
# A second vaccine with a lower efficacy
vax2 <- clone_epi(vax)
set_name_tool(vax2, "Vaccine (lower efficacy)")
set_susceptibility_reduction(vax2, 0.7)
#> Tool : Vaccine (lower efficacy)
#> Id : (empty)
#> state_init : -99
#> state_post : -99
#> queue_init : 0
#> queue_post : 0
add_tool(model, vax)
add_tool(model, vax2)
model
#> ________________________________________________________________________________
#> Susceptible-Infected-Removed (SIR) (connected)
#> It features 1000 agents, 1 virus(es), and 2 tool(s).
#> The model has 3 states. The model hasn't been run yet.
