1. Home
  2. How to run multiple versions of ASReml-R

How to run multiple versions of ASReml-R

Every now and then you may need to use more than one version of a given R library. This can occur for several reasons, including comparing old and new code, checking compatibilities in a workflow, preference for one or another version, etc.

However, the R environment only allows a single version of a given package to be loaded at a time. This is reasonable as a method of conveniently controlling function names. If we load a second library, the standard behaviour of R is to overwrite an existing version when a new one is installed.

There is not much we can do about loading different versions of a library into the same R session. However, we do have options to facilitate installing and managing versions that can be loaded and used on demand.

In this tutorial we will explore three different approaches to do this:

  1. Installing each version in a different directory so they don’t overwrite each other.
  2. Managing several local environments as done by the renv package.
  3. A unique workaround using asreml.

In the following examples, we will use two versions of VSNi’s asreml R package: version 4.1 and version 4.2. These versions are essentially the same in terms of users interface and code, but many things have changed in the backend leading to performance improvements. Hence, we are interested in comparing them in terms of behaviour, speed and consistency.

Let’s have a close look at each method, then you can choose the one that best fits your needs.

Setup: installing dependencies

Before exploring the different approaches, you will first need to install the libraries that asreml depends on.

install.packages(c("data.table", "ggplot2", "jsonlite"))

The downloaded packages can be found in:


Approach 1. Using different library directories

This is probably the best option for most users as it follows a straightforward logic. Also, it uses less disk space (something that will become clearer later). Nevertheless, if the library for which we want multiple versions (asreml in this case) also depends on different versions of another library (say, data.table), this approach becomes less useful. This is because you will need to install both versions of the target library and  any other dependency. Fortunately, this is not the case with asreml versions 4.1 and 4.2.

Installing asreml version 4.1

Normally, R libraries are installed in one of the paths that are easily accessed by calling: .libPaths(). Note that more than one path might be returned; below we are reporting just the first one ([1]).



Now we can proceed to install the library asreml, but we are not going to do this directly into the above path as both versions 4.1 and 4.2 will (conventionally) use the same directory name: “/asreml”. If we ignore this, the second installation will overwrite the first one.

So instead of installing it directly in the main path (as shown above) we are going to create a subdirectory called “/asreml41” (for asreml version 4.1) so it is not overwritten by version 4.2 when we install it later on. To do this use the following command:

dir.create(paste0(.libPaths()[1], "/asreml41"))
Updated on June 28, 2023

Was this article helpful?