By calling this function inside a slim_block
function call you can insert R objects
into the script using direct inlining. This function should generally only be used within a
slim_block
call
r_inline(object, delay = FALSE)
slimr_inline(object, delay = FALSE)
R object to inline into the SLiM script.
By default r_inline
will insert the
value of object
into the script when the script is
created (e.g. when slim_script
is called).
However, setting delay = TRUE
will delay the evaluation
of object
until the script is rendered instead (e.g. when
slim_script_render
is called). This allows you to
write a slimr_script
before you have an object available
to be inlined (e.g. it allows you to have a 'placeholder'
for an object you plan to generate in R later).
A character vector with the code generated for inlining.
Currently supported R objects include all atomic vectors, matrices and arrays and RasterLayer
objects.
Non-atomic vectors like factors are currently not supported and neither are any other special object types, though we
plan to support some in the future.
popsizes <- c(100, 200, 300)
slim_script(
slim_block(initialize(),
{
initializeMutationRate(1e-7);
initializeMutationType("m1", 0.5, "f", 0.0);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, 99999);
initializeRecombinationRate(1e-8);
}),
slim_block(1,
{
popsizes <- r_inline(popsizes)
sim.addSubpop("p1", popsizes[1]);
sim.addSubpop("p2", popsizes[2]);
sim.addSubpop("p3", popsizes[3]);
}),
slim_block(10000,
{
sim.simulationFinished();
})
)
#> Error in purrr::map2(code, slimr_inline_attr, ~gather_inline_one(.x, .y)): ℹ In index: 2.
#> Caused by error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `.f()`:
#> ! object 'popsizes' not found