Skip to content

mrgsolve Installation

Kyle Baron edited this page Jul 13, 2021 · 41 revisions

Installation guide

Prerequisites

  • R: https://cran.r-project.org/
    • Currently R >= 3.1.2 is required
    • R should be installed locally, not on a network drive or on a drive that is synced to a remote (like Google Drive, DropBox, OneDrive, etc.)
  • Seriously consider running in Rstudio if possible. This is not required but is recommended.
  • Compilers: C++ and gfortran (see the Compilers section below)

No networked or synced drives

Don’t try to run mrgsolve on a network drive. R should be running from your local compute resources and the R files you are working on should be located on local disk space. Avoid any interaction with a network drive or a drive that is synced with a cloud service (like Google Drive, DropBox, OneDrive or the like).

Compilers (buid tools)

Current versions of C++ and FORTRAN compilers are required to use mrgsolve. Available compilers and requirements may vary by operating system. Please see system-specific instructions below. But note well that the toolchain that needs to be in place is the usual toolchain required for ordinary use of R (either to compile R from source or to compile R packages from source). There is very detailed and complete information on compilers to use with R on the r-project website (https://cran.r-project.org/doc/manuals/R-admin.html and see links below). There are no special compiler requirements to get mrgsolve up and running; just install the compilers you would normally need to use with R and mrgsolve will compile and you will be able to compile your mrgsolve models.

Windows users

You need to download and properly install the Windows toolset (Rtools). Do not use any compiler other than the one provided by the r-project. You MUST use Rtools. Please update to a recent version even if you think you already have it installed.

R 4.0 and later

There is a pretty good install page here: https://cran.r-project.org/bin/windows/Rtools/index.html

Since you are using R 4.x, then you’ll need the rtools40 bundle of compilers and system utils. The replaces the older RtoolsXX versions (see below). The install instructions are very well written and precise; they should be followed carefully. Like previous iterations of Rtools, you’ll need to pay attention to the PATH where rtools40 is installed.

R 3.x

If you are using R 3.x, then you need to install an older version of Rtools than what is currently in use. You can ccess these legacy Rtools versions here:

  • Download RtoolsXX.exe from this page
    • XX is the version number (e.g. Rtools35.exe)
    • Get the version number that corresponds to your version of R
    • Do not get a version that is not frozen yet
  • Install RtoolsXX.exe
    • When you are installing, pay attention for a prompt asking about changing the PATH; make sure that the installer updates PATH; you might have to opt in to this path modification
  • Check your PATH environment variable in R
    • Use the command Sys.getenv("PATH") in R, after restarting to make sure the proper directories are listed there. R will not find the toolchain unless the PATH is correctly
    • If PATH is not properly set, try to set it with a system-wide environment variable
    • If a system-wide environment variable is not posible, there are some other very good options here
  • Common error messages from incorrect Windows installs can be found here

See also

macos

Install C++ and gfortran compilers found here: https://cran.r-project.org/bin/macosx/tools/

macos notes

Make sure to take note of the R version you are using as the build toolchain changed when R version 4 was released. If you are using R 4.x, you will need the Xcode compiler as well as a gfortran compiler. If you are using an earlier version of R, these requirements are slightly different. In either case, use the gfortran compiler recommended by the R project. As of July 2021, this is gfortran 8.4. Note: the version recommended by r-project might not be the most recent version and it might be a version that appears to be associated with an earlier version of macos. But follow the link above and use what is recommended there.

Unix users

UNIX usually include C++ and FORTRAN compliers. If not, install gcc.

Troubleshooting installation

You can use the pkgbuild package to test if the required build tools are available.

library(pkgbuild)

check_build_tools(debug = TRUE)
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## ccache /usr/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## ccache /usr/bin/clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o foo.so foo.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

## 

## Your system is ready to build packages!

You can also check for the presence of a system utility

Sys.which("make")
##            make 
## "/usr/bin/make"

or tap other diagnostics provided by pkgbuild

pkgbuild::has_build_tools()
## [1] TRUE
pkgbuild::has_compiler(debug = TRUE)
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## ccache /usr/bin/clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o foo.so foo.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

## 

## [1] TRUE

Test the installation

You can run some code to test that mrgsolve can run a model

library(mrgsolve)
?mrgsolve
example("mrgsolve")