Write a slimr_script object to a text file, which can be run in SLiM as a SLiM script

slimr_write(x, file, ...)

Arguments

x

slimr_script object to write to file

file

File path to write to

...

Further arguments to be passed to or from other objects

Value

Returns x, invisibly

Examples

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", 500);
          }),
   slim_block(10000,
          {
            sim.simulationFinished();
          })
) -> script
temp_file <- tempfile(fileext = ".txt")
slimr_write(script, temp_file)
readLines(temp_file)
#>  [1] "initialize() {"                                    
#>  [2] "    initializeMutationRate(1e-07);"                
#>  [3] "    initializeMutationType(\"m1\", 0.5, \"f\", 0);"
#>  [4] "    initializeGenomicElementType(\"g1\", m1, 1);"  
#>  [5] "    initializeGenomicElement(g1, 0, 99999);"       
#>  [6] "    initializeRecombinationRate(1e-08);"           
#>  [7] "}"                                                 
#>  [8] ""                                                  
#>  [9] "1 early() {"                                       
#> [10] "    sim.addSubpop(\"p1\", 500);"                   
#> [11] "}"                                                 
#> [12] ""                                                  
#> [13] "10000 early() {"                                   
#> [14] "    sim.simulationFinished();"                     
#> [15] "}"                                                 
#> [16] ""