Installation of Rstan package for R

Hello all,

I write here to ask if it would be possible to install the Rstan package on R?

Process for the installation is described in details here: RStan Getting Started · stan-dev/rstan Wiki · GitHub

Many thanks for all your help!!

Hello @Maxime.Walder

The procedure is quite different from which we talk about earlier.

For the R package, you can do it yourself easily:
:warning: The Rstan package does not seem to work for R >= 4.2.0

1. Load R module + nodejs

(baobab)-[alberta@login2 ~]$ R_LIBS=~/Rpackages/
(baobab)-[alberta@login2 ~]$ mkdir ~/Rpackages
(baobab)-[alberta@login2 ~]$ ml GCC/10.3.0  OpenMPI/4.1.1  R/4.1.0 nodejs

2. Create the stan install file ( described in the link you provide :wink: )

(baobab)-[alberta@login2 ~]$ cat install_Rstan.r 
# run the next line if you already have rstan installed
# remove.packages(c("StanHeaders", "rstan"))
# next line commented cause we load nodejs before
# Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1) # only necessary for Linux without the nodejs library / headers
install.packages("rstan", repos = "", dependencies = TRUE)

3. install Rstan package running R script

:warning: Compiling on login2 does not allowed to run computation on login node.
You can even compile via slurm :sunglasses:

(baobab)-[alberta@login2 ~]$ time Rscript test_lib.R

4. Verify Rstan is available:

(baobab)-[alberta@login2 ~]$ time Rscript test_lib.R 
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.8, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)

real	0m2.210s
user	0m1.750s
sys	0m0.235s

Let me know if it’s good for you.

1 Like

It works all fine!!

Merci beaucoup !! :slight_smile: