12

I'm not able to install rstanarm on R 3.5.3 running on Ubuntu 18.04 LTS. I used the following commands:

install.packages("rstanarm")

and

devtools::install_github("stan-dev/rstanarm", build_vignettes = FALSE)

and both throws the following error:

Execution halted
Makevars:17: recipe for target 'stan_files/lm.cc' failed
make: *** [stan_files/lm.cc] Error 1
ERROR: compilation failed for package ‘rstanarm’

sessionInfo

sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] usethis_1.5.0  devtools_2.0.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        ps_1.3.0          prettyunits_1.0.2 rprojroot_1.3-2  
 [5] digest_0.6.18     crayon_1.3.4      withr_2.1.2       assertthat_0.2.1 
 [9] R6_2.4.0          backports_1.1.3   magrittr_1.5      rlang_0.3.4      
[13] cli_1.1.0         curl_3.3          fs_1.2.7          remotes_2.0.2    
[17] testthat_2.0.1    callr_3.2.0       desc_1.2.0        tools_3.5.3      
[21] glue_1.3.1        pkgload_1.0.2     compiler_3.5.3    processx_3.3.0   
[25] pkgbuild_1.0.3    sessioninfo_1.1.1 tcltk_3.5.3       memoise_1.1.0    
> 
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
  • Do you have everything from https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux#c-toolchain-configuration ? – Ben Goodrich Apr 10 '19 at 12:45
  • Since you are using a newer Ubuntu, it's unlikely, but worth checking g++ version. – amatsuo_net Apr 10 '19 at 13:37
  • Thanks @BenGoodrich for your comment. I've already attempted all this but still it is not working. Any thoughts. Thanks – MYaseen208 Apr 13 '19 at 09:36
  • 1
    What is shown **before** the words `Execution halted`? – duckmayr Apr 13 '19 at 10:47
  • @duckmayr: `"/usr/lib/R/bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/lm.stan Error: (converted from warning) S3 methods 'print.stanfit', 'as.array.stanfit', 'as.matrix.stanfit', 'as.data.frame.stanfit', 'is.array.stanfit', 'dim.stanfit', 'dimnames.stanfit', 'names.stanfit', 'names<-.stanfit', 'pairs.stanfit', 'loo.stanfit' were declared in NAMESPACE but not found` – MYaseen208 Apr 13 '19 at 10:52
  • @MYaseen208 Have you tried (from the terminal) `sudo apt update` then `sudo apt install r-cran-rstan`? – duckmayr Apr 13 '19 at 10:57
  • @duckmayr: Yes, I've alread tried `sudo apt update` and then `sudo apt install r-cran-rstan` which throws the error: ` E: Unable to locate package r-cran-rstan`. Any thoughts – MYaseen208 Apr 13 '19 at 11:01
  • @MYaseen208 Sorry, I forgot to add that you need to add the PPAs first: `sudo add-apt-repository -y "ppa:marutter/rrutter"` and `sudo add-apt-repository -y "ppa:marutter/c2d4u"` – duckmayr Apr 13 '19 at 11:02
  • @duckmayr: I also added the PPAs – MYaseen208 Apr 13 '19 at 11:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/191779/discussion-between-duckmayr-and-myaseen208). – duckmayr Apr 13 '19 at 11:15
  • do you have a `.RProfile` file either in you home directory or in `R` directory , if you do ,then please can you share the content of it here or add it to your question ? – WaLid LamRaoui Apr 19 '19 at 23:12

2 Answers2

13

On Ubuntu 18.04 + R 3.5.3, you can install rstanarm via the following:

sudo add-apt-repository -y "ppa:marutter/rrutter"
sudo add-apt-repository -y "ppa:marutter/c2d4u3.5"
sudo apt update
sudo apt install r-cran-rstanarm

Some background info on why you may have had trouble previously:

The RStan installation guide for Ubuntu is out of date for those using R 3.5.x.

Ben Goodrich linked in the comments to the RStan GitHub Guide to Installing RStan on Linux. There they advise the following for Ubuntu:

# Add marutter's c2d4u repository, (and rrutter for CRAN builds too)
sudo add-apt-repository -y "ppa:marutter/rrutter"
sudo add-apt-repository -y "ppa:marutter/c2d4u"
sudo apt-get update
sudo apt-get install r-cran-rstan

However, for newer versions of R, you need to instead do the following

# Add marutter's c2d4u repository, (and rrutter for CRAN builds too)
sudo add-apt-repository -y "ppa:marutter/rrutter"
sudo add-apt-repository -y "ppa:marutter/c2d4u3.5"
sudo apt-get update
sudo apt-get install r-cran-rstan

This should install RStan for you just fine on Ubuntu 18.04 + R 3.5.3.

duckmayr
  • 16,303
  • 3
  • 35
  • 53
  • Got installed. However, `library(rstanarm)` throws the following `Error: package or namespace load failed for ‘rstanarm’ in library.dynam(lib, package, package.lib): shared object ‘rstanarm.so’ not found`. Any thoughts, please. – MYaseen208 Apr 13 '19 at 14:37
  • @MYaseen208 Does running `find . -name 00LOCK-rstan*` from the terminal (from your home directory) return anything? – duckmayr Apr 13 '19 at 18:20
  • Did not find anything. – MYaseen208 Apr 14 '19 at 05:50
1

First time when this error occured and assuming that you have a .RProfile in your R root directory you will most likely find a line where it says : setwd("~/R") ,go ahead and comment this line and restart R and get a new session , then run again : install.packages("rstanarm") you should be able to install rstanarm successfully , don't forget to uncomment setwd("~/R") after the installation , the reason of the this error to occur is that rstanarm install script assumes that the working directory is the root of the package directory which not the case when you call setwd() in .Rprofile if you want to give this a try .. please remove the rstanarm that you installed using PPA

WaLid LamRaoui
  • 2,305
  • 2
  • 15
  • 33