README.md

slimrlang

R build
status Codecov test
coverage Lifecycle:
experimental

The goal of slimrlang is to provide an environment in which you can write SLiM population genetics simulation scripts from R. It works particularly well with RStudio, but any R IDE can be used. For much more advanced functionality in running and processing SLiM simulations from R, see the slimr package which imports slimrlang.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("rdinnager/slimrlang")

Example

Using slimrlang, this is how you write the first example script (or recipe) from the (excellent) SLiM manual:

library(slimrlang)

slim_script(
  slim_block(initialize(),
             {
               ## set the overall mutation rate
               initializeMutationRate(1e-7); 
               ## m1 mutation type: neutral
               initializeMutationType("m1", 0.5, "f", 0.0);
               ## g1 genomic element type: uses m1 for all mutations
               initializeGenomicElementType("g1", m1, 1.0);
               ## uniform chromosome of length 100 kb
               initializeGenomicElement(g1, 0, 99999);
               ## uniform recombination along the chromosome
               initializeRecombinationRate(1e-8);
             }),
  slim_block(1,
             {
               sim.addSubpop("p1", 500);
             }),
  slim_block(10000,
             {
               sim.simulationFinished();
             })
) -> script_1

script_1
#> <slimr_script[3]>
#> block_init:initialize() {
#>     initializeMutationRate(1e-07);
#>     initializeMutationType("m1", 0.5, "f", 0);
#>     initializeGenomicElementType("g1", m1, 1);
#>     initializeGenomicElement(g1, 0, 99999);
#>     initializeRecombinationRate(1e-08);
#> }
#> 
#> block_2:1 early() {
#>     sim.addSubpop("p1", 500);
#> }
#> 
#> block_3:10000 early() {
#>     sim.simulationFinished();
#> }

You can output this script to text to run in a standalone SLiM installation, or you can run it in SLiM directly from R using functions from the companion R package slimr.

You can also do fancy stuff like make the above script or another script into a template that you can dynamically fill-in with parameters generated in R. You can also make SLiM generate R-friendly input. See the vignettes for details of these features and how to use them.



rdinnager/slimrlang documentation built on June 20, 2020, 8:17 p.m.