slendr is available on the CRAN R package repository. As
such, you can install it simply by executing
install.packages("slendr") in your R console.
If you want (or need) to get its development version, you can install
it directly from GitHub by executing
devtools::install_github("bodkan/slendr") via the R package
devtools (you can gen devtools by running
install.packages("devtools")). In fact, if you decide to
try slendr, please make sure to update it regularly and keep an
eye on the changelog on a regular
basis! This is where you can find information about latest bugfixes and
potential breaking changes.
Once you install slendr, calling
library(slendr) will check that all software dependencies
are available. If they are not, the R package will provide a
brief helpful guide on how to resolve potential issues. The rest of this
vignette talks about the necessary software dependencies in a bit more
Please note that slendr is fully supported only on
macOS and Linux at the moment. That said, there is an
experimental support for running coalescent simulation via
slendr’s Python backend
msprime() and for
analyzing tree-sequence outputs using its tskit interface.
slendr relies on three main software dependencies:
geospatial data analysis R package sf (for encoding spatial slendr models and analysing spatial tree-sequence data),
forward population genetic simulator SLiM (for forward simulations),
Python modules tskit, msprime, and pyslim (for coalescent simulations and tree-sequence analysis).
All three are widely used in their respective fields and, as such, are easily obtainable on all major operating systems (see below for more information on how to troubleshoot potential problems).
Note that depending on your use case, not all three sets of dependencies will be necessarily needed. If you’re not going to be running forward spatial simulations, you don’t need SLiM. If you don’t want to analyze tree sequences in R, you won’t necesarily need slendr’s Python dependencies.
In this vignette, I will briefly explain how to get all slendr’s software dependencies installed. That said, note that under normal circumstances (with the exception of SLiM), no manual installation of individual dependencies is required.
The R package sf is at the heart of geospatial data analysis
in R. It is available on CRAN and can be installed for all major
platforms by executing
install.packages("sf") in your R
When you install slendr (see the very top of this page), the installation procedure will automatically install sf for you. Under normal circumstances, you should not have to worry about sf at all.
That said, sf itself depends on a number of geospatial libraries and depending on the exact setup of your Linux or macOS machine, some of those libraries could be missing. Luckily, all of them are very easy to install via Homebrew (on macOS) or via the appropriate package manager of your Linux distribution (Ubuntu, Fedora, etc.). Detailed instructions on how to do this for your operating system can be found here.
If you’re having trouble installing slendr in your R
session, it’s worth testing whether you can run
install.packages("sf") and successfully load
library(sf). In nearly 100% cases of my test
cases, if a slendr installation failed, it was due to a problem
with some missing dependency of sf. If you’re having these
problems, look for help here.
One user who recently installed slendr on a fresh macOS
system reported that they needed to install
order to be able to install the package devtools for the
devtools::install_github("bodkan/slendr") step described on
top of this page.
Additionally, they had to install a couple of C/C++ libraries as well (all dependencies of the sf package). In the end, they were able to successfully install slendr after running:
brew install libgit2 udunits gdal proj
Note that this assumes that you have the Homebrew package manager already setup on your Mac. If you’re a beginning computational scientist using a Mac, I strongly encourage you to install Homebrew. Sooner or later you will need some specific Linux/unix program anyway, and Homebrew is the way to get it (Mac is a unix machine, but without Homebrew a very poor one by default).
Testing slendr installation on a fresh, pristine Debian installation with no dependencies previously installed, I had to run the following:
sudo apt-get install libudunits2-dev libssl-dev libgdal-dev libgsl-dev libgit2-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev
It’s very unlikely you would need all of the above (and you might need other packages on non-Debian distributions), but this is what got slendr and all of its dependencies running on a completely clean system. Might be a good start in case you have trouble on your Linux machine.
The forward population genetic software SLiM is available on all
major software platforms. Its complete installation instructions can be
found here. On a Mac, I
recommend installing SLiM via the
pkg installer available
for direct download from its website. On Linux, you can either
install SLiM via the appropriate package manager for your Linux
distribution (see SLiM manual here for more information), or
you can easily compile your own.
Note that slendr requires SLiM 4.0 and will not work with an
earlier version. Again, running
library(slendr) will inform
you of any potential issues with your SLiM installation.
In order to be able to run coalescent simulations and process tree-sequence files, slendr needs Python modules tskit, msprime, and pyslim.
Setting up an isolated Python environment with specific version of Python packages (which is very important to avoid clashes among different Python programs needed by your system) can be a bit of a hassle for some users. This is especially true for R users who might not use Python in their daily work, such as yours truly.
In order to make sure that the R package has the most appropriate
version of Python available, with the correct versions of all of its
Python module dependencies, slendr provides a dedicated
setup_env() which automatically downloads
a completely separate Python distribution and installs the required
versions of tskit, msprime, and pyslim
modules into a dedicated virtual environment. Moreover, this
Python installation and virtual environment are entirely
isolated from other Python configurations that are already present on
the user’s system, avoiding potential conflicts with the
versions of Python and Python modules required by slendr.
Next time you call
library(slendr), you will
need to activate this environment automatically by calling
init_env(). If you’re not comfortable with Python
you don’t need to worry beyond calling
init_env(), no interaction with Python is necessary for
working with slendr in R.
In case you are wondering how does slendr accomplish the above: slendr’s Python interface is not a hack that would simply call Python from the command-line in the background, but is implemented using the R package reticulate. This embeds a Python session within an R session, enabling high-performance interoperability between both languages without any need for user intervention.
There is currently no official Docker image for slendr but there will be once the R package finally lands on the official CRAN repository. The current plan is to use the geospatial image published by the Rocker project (which already contains pre-compiled R, RStudio, and all necessary R package dependencies such as sf ) and extend it with slendr and SLiM.
TODO: Advertise the renv solution for managing reproducible environments for R packages.