R/slimr_scripting.R
slim_script_render.Rd
If your slimr_script
object has made use of special slimrlang
syntax slimr_template
, this function will 'render' the slimr_script
into valid SLiM syntax, ready to be run with SLiM or slim_run
slim_script_render(
slimr_script,
template = NULL,
replace_NAs = TRUE,
reps = 1,
parallel = FALSE,
portable = FALSE
)
The slimr_script
object to be rendered
A list or data.frame containing values for any templated variables. If a list,
it must be named, where the names correspond to the variables. If a list of lists, the inner
lists must be named with the variable names, and slim_script_render
will render a
separate slimr_script
for each top-level list element and return it as a slimr_script_coll
object. If a data.frame
(or tibble
), then the column names should match the templated
variables, and slim_script_render
will render a separate slimr_script
for each row
and return it as a slimr_script_coll
object.
Should NA
values in the template be replaced by their default values?
Should the rendered script be replicated? If greater than 1, a slimr_script_coll
will be returned. This can also be used with a slimr_script
object that has already been
rendered, in which case it will just repeat the rendered script in the result.
Should the rendering be done in parallel when rendering multiple scripts? Requires
the furrr
package and will use the plan set by future::plan
If `TRUE`, the the script will be rendered in a 'portable' format, which allows the script to be modified in another program such as SLiMGUI, and then reimported into R, while maintaining `slimr` features. See details for more information on how this works.
A rendered `slimr_script_coll` object
test_sim <- slim_script(
slim_block_init_minimal(mutation_rate = r_template("mu", 1e-7)),
slim_block_add_subpops(1, 100),
slim_block(1, 20, late(), {
r_output(sim.outputFull(), "out", do_every = 10)
})
) %>%
slim_script_render(data.frame(mu = c(1e-7, 1e-6, 1e-5)))
test_sim
#> <slimr_script_coll[3]>
#> <1>
#>
#> block_init:initialize() {
#> initializeMutationRate(1e-07);
#> initializeMutationType("m1", 0.5, "f", 0);
#> initializeGenomicElementType("g1", m1, 1);
#> initializeGenomicElement(g1, 0, 1e+05 - 1);
#> initializeRecombinationRate(1e-08);
#> }
#>
#> block_2:1 early() {
#> sim.addSubpop("p1", 100);
#> }
#>
#> block_3:1:20 late() {
#> {sim.outputFull() -> out}
#> }
#>
#> <2>
#>
#> block_init:initialize() {
#> initializeMutationRate(1e-06);
#> initializeMutationType("m1", 0.5, "f", 0);
#> initializeGenomicElementType("g1", m1, 1);
#> initializeGenomicElement(g1, 0, 1e+05 - 1);
#> initializeRecombinationRate(1e-08);
#> }
#>
#> block_2:1 early() {
#> sim.addSubpop("p1", 100);
#> }
#>
#> block_3:1:20 late() {
#> {sim.outputFull() -> out}
#> }
#>
#> <3>
#>
#> block_init:initialize() {
#> initializeMutationRate(1e-05);
#> initializeMutationType("m1", 0.5, "f", 0);
#> initializeGenomicElementType("g1", m1, 1);
#> initializeGenomicElement(g1, 0, 1e+05 - 1);
#> initializeRecombinationRate(1e-08);
#> }
#>
#> block_2:1 early() {
#> sim.addSubpop("p1", 100);
#> }
#>
#> block_3:1:20 late() {
#> {sim.outputFull() -> out}
#> }