R/slim_extract.R
slim_results_to_data.Rd
This function tries to automate the process of converting
output in the slimr_results
object returned by
slim_run
function into usable data in the
form of a tibble
. If this process fails you will
end up with the data as a character string, and you will
have to manually convert this into something you can use.
slim_results_to_data(dat, generations = NULL)
A slimr_results
object to extract data from.
You can alternatively specify the output_data
from the slimr_results
directly in this parameter.
For what generations do you want to extract data?
Default is all generations that have data. The special value 0
can be used to specify just the most recent generation in the data.
A tibble with three columns, name: the name of the outputs, generation: the generations of the outputs, and data: the outputs as converted data. This final column will be a list column, where each element will usually be a vector or a tibble, depending on what kind of data was returned by the simulation.
if(slim_is_avail()) {
test_sim <- slim_script(
slim_block_init_minimal(),
slim_block_add_subpops(1, 100),
slim_block(1, 20, late(), {
r_output(sim.outputFull(), "out", do_every = 10)
})
) %>%
slim_run()
slim_results_to_data(test_sim)
}
#>
#>
#> Simulation finished with exit status: 0
#>
#> Success!
#> # A tibble: 2 × 5
#> type expression generation name data
#> <chr> <chr> <int> <chr> <list>
#> 1 slim_output sim.outputFull() 10 out <slmr_tF_ [3]>
#> 2 slim_output sim.outputFull() 20 out <slmr_tF_ [3]>