Use this function in a slim_block call and it will be converted in the SLiM script into code to make formatted output. This output can easily be read into R and even dynamically read during simulation runs with slim_run from the slimr package. This function should generally only be used within a slim_block call

r_output(
  slimr_expr,
  name,
  do_every = 1,
  send_to = c("data", "file"),
  file_name = tempfile(fileext = ".txt"),
  format = c("csv", "fst"),
  type = NULL,
  expression = NULL,
  time_counter = community.tick
)

slimr_output(
  slimr_expr,
  name,
  do_every = 1,
  send_to = c("data", "file"),
  file_name = tempfile(fileext = ".txt"),
  format = c("csv", "fst"),
  type = NULL,
  expression = NULL,
  time_counter = community.tick
)

Arguments

slimr_expr

A SLiM expression to generate output. This can either be a SLiM expression designed to create output, such as outputFull(), or an object created in the SLiM code, in which case r_output will automatically concatenate it to a string and output it

name

The name to use to identify this output.

do_every

How often should the output be produced? Expressed as an integer saying how many generations to run before producing output. e.g. do_every = 10 means to output every 10 generations of the simulation.

send_to

*deprecated* Where to send the output? This could be used to send the output to be stored in the results object ("data"), or to an external file ("file"). This will no longer be available in future versions in favour of an option to have the results stored as a pointer to an external file (to save memory).

file_name

*deprecated* The file name to save output to if send_to = "file"

format

*deprecated* The file format to save data if send_to = "file", Only "csv" is implemented but there are plans to support "fst" and "disk.frame".

type

Provide a custom type to the output. Used mostly for internal purposes.

expression

Provide a custom expression to be included with the output. Used mostly for internal purposes.

time_counter

Expression used to extract the simulation time from SLiM. By default this uses the global timing mechanism in SLiM version >4.0: `community.tick`. For versions <4.0, use `sim.generation` instead (this parameter is for backwards compatability with old SLiM versions)

Value

An expression with the code to be run in SLiM.

Examples

if(slim_is_avail()) {
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,
             {
               sim.addSubpop("p1", 100);
             }),
  slim_block(100,
             {
               r_output(p1.outputVCFSample(sampleSize = 10), name = "VCF");
               sim.simulationFinished();
             })
) %>%
slim_run() -> run_w_out

cat(run_w_out$output_data$data[[1]])
}
#> 
#> 
#> Simulation finished with exit status: 0
#> 
#> Success!
#> #OUT: 100 100 SV p1 10
#> ##fileformat=VCFv4.2
#> ##fileDate=20231221
#> ##source=SLiM
#> ##INFO=<ID=MID,Number=.,Type=Integer,Description="Mutation ID in SLiM">
#> ##INFO=<ID=S,Number=.,Type=Float,Description="Selection Coefficient">
#> ##INFO=<ID=DOM,Number=.,Type=Float,Description="Dominance">
#> ##INFO=<ID=PO,Number=.,Type=Integer,Description="Population of Origin">
#> ##INFO=<ID=TO,Number=.,Type=Integer,Description="Tick of Origin">
#> ##INFO=<ID=MT,Number=.,Type=Integer,Description="Mutation Type">
#> ##INFO=<ID=AC,Number=.,Type=Integer,Description="Allele Count">
#> ##INFO=<ID=DP,Number=1,Type=Integer,Description="Total Depth">
#> ##INFO=<ID=MULTIALLELIC,Number=0,Type=Flag,Description="Multiallelic">
#> ##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
#> #CHROM	POS	ID	REF	ALT	QUAL	FILTER	INFO	FORMAT	i0	i1	i2	i3	i4	i5	i6	i7	i8	i9
#> 1	61727	.	A	T	1000	PASS	MID=187;S=0;DOM=0.5;PO=1;TO=97;MT=1;AC=2;DP=1000	GT	0|0	0|0	0|0	0|0	0|0	1|0	0|0	1|0	0|0	0|0