Problems with rstan in R 4.0.0 and R 3.6.3

Hello, i’ve working with Rstudio and rstan for university tasks and due to a problem with ggplot2, i ve been forced to uninstall r, rstudio and rtools to try fixing it. I ve testing R 4.0.0 and R 3.6.3 and i have got several problems with both versions that doesn´t allow me to run rstan in neither of those. Both problems happen in rstudio 1.2

  • R 4.0.0
		-writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
		-Sys.which("make")
			## "C:\\rtools40\\usr\\bin\\make.exe"

Before this, all clear, no error.

		-install.packages("jsonlite", type = "source") 
  • when rtools was installed properly, ggplot2 is not found due rlang. i paste the following ouput
		- R/win-library/4.0’
	(as ‘lib’ is unspecified)
	probando la URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/rlang_0.4.5.zip'
	Content type 'application/zip' length 1110537 bytes (1.1 MB)
	downloaded 1.1 MB

	package ‘rlang’ successfully unpacked and MD5 sums checked

	The downloaded binary packages are in
		C:\Users\Álvaro López\AppData\Local\Temp\Rtmps5SWLZ\downloaded_packages
	> library(rlang)
	Error: package or namespace load failed for ‘rlang’ in get(Info[i, 1], envir = env):
	 no fue posible abrir el archivo 'C:/Users/Álvaro López/Documents/R/win-library/4.0/rlang/R/rlang.rdb': No such file or directory
	> library(rstan)
	Loading required package: StanHeaders
	Loading required package: ggplot2
	Error: package or namespace load failed for ‘ggplot2’ in get(Info[i, 1], envir = env):
 no fue posible abrir el archivo 'C:/Users/Álvaro López/Documents/R/win-library/4.0/rlang/R/rlang.rdb': No such file or directory
	Error: package ‘ggplot2’ could not be loaded
	> rstan_options(auto_write=TRUE)
	Error in rstan_options(auto_write = TRUE) : 
  	no se pudo encontrar la función "rstan_options" 
  • R 3.6.3

    -rtools doesn´t install, when i write library(“rstan”), the following output is

		- Loading required package: StanHeaders
			Loading required package: ggplot2
			rstan (Version 2.19.3, 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)
			For improved execution time, we recommend calling
			Sys.setenv(LOCAL_CPPFLAGS = '-march=corei7 -mtune=corei7')
			although this causes Stan to throw an error on a few processors.

-rtools doesn´t end installing, when i introduce a stan code. RStudio asks me “Building R package from source requires installation of additional buy tools. Do you want to install the additional tools now?”
- i accept, introduce the code for the second time and RStudio asks me the same question. If i refuse, it appears the following output

		- Error in compileCode(f, code, language = language, verbose = verbose) : 
  			Compilation ERROR, function(s)/method(s) not created! make: 			"C:/Users/Álvaro López/Documents/.R/Makevars.win": No such file or directory
			make: *** No rule to make target '"C:/Users/Álvaro 			López/Documents/.R/Makevars.win"'.  Stop.
			Además: Warning message:
			In system(cmd, intern = !verbose) :
  			comando ejecutado 'C:/PROGRA~1/R/R-36~1.3/bin/x64/R CMD SHLIB 			file36f031e12d62.cpp 2> file36f031e12d62.cpp.err.txt' tiene estatus 1
			Error in sink(type = "output") : conexión inválida

This is the stan code which i ve been testing

library(rstan)
y<-c(15,28,16,12,29,33,48,23,15,33,41,49,18,4,59,73,27,16,14,29)
x<-c(8,5,7,8,5,4,4,5,6,5,4,4,6,10,3,2,6,6,9,5)
n<-length(y)
datos<-list(n=n,y=y,x=x)
codigo <- "
data{
int n;
int x[n];
int y[n];
}
parameters {
real tau ;
real omega;
}
model {
real lambda;
tau ~ normal(0,4);
omega ~ normal(0,4);
for(i in 1:n){
lambda = exp(tau + omega*x[i]);
y[i] ~ poisson(lambda);
}
}
"
fit_stan <- stan(model_code = codigo, data=datos)
print(fit_stan)
  • Operating System - I think it is below
  • RStan Version 2.19.3
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
Error in file(con, "r") : no se puede abrir la conexión
Además: Warning message:
In file(con, "r") :
  cannot open file 'C:\Users\Álvaro López\Documents/.R/Makevars': No such file or directory
  • Output of devtools::session_info("rstan")
- Session info ----------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.3 (2020-02-29)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  Spanish_Spain.1252          
 ctype    Spanish_Spain.1252          
 tz       Europe/Paris                
 date     2020-05-01                  

- Packages --------------------------------------------------------------------------------------------------------------------------------------
 package      * version   date       lib source        
 assertthat     0.2.1     2019-03-21 [1] CRAN (R 3.6.3)
 backports      1.1.6     2020-04-05 [1] CRAN (R 3.6.3)
 BH             1.72.0-3  2020-01-08 [1] CRAN (R 3.6.2)
 callr          3.4.3     2020-03-28 [1] CRAN (R 3.6.3)
 checkmate      2.0.0     2020-02-06 [1] CRAN (R 3.6.3)
 cli            2.0.2     2020-02-28 [1] CRAN (R 3.6.3)
 colorspace     1.4-1     2019-03-18 [1] CRAN (R 3.6.1)
 crayon         1.3.4     2017-09-16 [1] CRAN (R 3.6.3)
 desc           1.2.0     2018-05-01 [1] CRAN (R 3.6.3)
 digest         0.6.25    2020-02-23 [1] CRAN (R 3.6.3)
 ellipsis       0.3.0     2019-09-20 [1] CRAN (R 3.6.3)
 evaluate       0.14      2019-05-28 [1] CRAN (R 3.6.3)
 fansi          0.4.1     2020-01-08 [1] CRAN (R 3.6.3)
 farver         2.0.3     2020-01-16 [1] CRAN (R 3.6.3)
 ggplot2      * 3.3.0     2020-03-05 [1] CRAN (R 3.6.3)
 glue           1.4.0     2020-04-03 [1] CRAN (R 3.6.3)
 gridExtra      2.3       2017-09-09 [1] CRAN (R 3.6.3)
 gtable         0.3.0     2019-03-25 [1] CRAN (R 3.6.3)
 inline         0.3.15    2018-05-18 [1] CRAN (R 3.6.3)
 isoband        0.2.1     2020-04-12 [1] CRAN (R 3.6.3)
 labeling       0.3       2014-08-23 [1] CRAN (R 3.6.0)
 lattice        0.20-38   2018-11-04 [2] CRAN (R 3.6.3)
 lifecycle      0.2.0     2020-03-06 [1] CRAN (R 3.6.3)
 loo            2.2.0     2019-12-19 [1] CRAN (R 3.6.3)
 magrittr       1.5       2014-11-22 [1] CRAN (R 3.6.3)
 MASS           7.3-51.5  2019-12-20 [2] CRAN (R 3.6.3)
 Matrix         1.2-18    2019-11-27 [2] CRAN (R 3.6.3)
 matrixStats    0.56.0    2020-03-13 [1] CRAN (R 3.6.3)
 mgcv           1.8-31    2019-11-09 [2] CRAN (R 3.6.3)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 3.6.3)
 nlme           3.1-144   2020-02-06 [2] CRAN (R 3.6.3)
 pillar         1.4.3     2019-12-20 [1] CRAN (R 3.6.3)
 pkgbuild       1.0.7     2020-04-25 [1] CRAN (R 3.6.3)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 3.6.3)
 pkgload        1.0.2     2018-10-29 [1] CRAN (R 3.6.3)
 praise         1.0.0     2015-08-11 [1] CRAN (R 3.6.3)
 prettyunits    1.1.1     2020-01-24 [1] CRAN (R 3.6.3)
 processx       3.4.2     2020-02-09 [1] CRAN (R 3.6.3)
 ps             1.3.2     2020-02-13 [1] CRAN (R 3.6.3)
 R6             2.4.1     2019-11-12 [1] CRAN (R 3.6.3)
 RColorBrewer   1.1-2     2014-12-07 [1] CRAN (R 3.6.0)
 Rcpp           1.0.4.6   2020-04-09 [1] CRAN (R 3.6.3)
 RcppEigen      0.3.3.7.0 2019-11-16 [1] CRAN (R 3.6.3)
 rlang          0.4.5     2020-03-01 [1] CRAN (R 3.6.3)
 rprojroot      1.3-2     2018-01-03 [1] CRAN (R 3.6.3)
 rstan        * 2.19.3    2020-02-11 [1] CRAN (R 3.6.3)
 rstudioapi     0.11      2020-02-07 [1] CRAN (R 3.6.3)
 scales         1.1.0     2019-11-18 [1] CRAN (R 3.6.3)
 StanHeaders  * 2.21.0-1  2020-01-19 [1] CRAN (R 3.6.2)
 testthat       2.3.2     2020-03-02 [1] CRAN (R 3.6.3)
 tibble         3.0.1     2020-04-20 [1] CRAN (R 3.6.3)
 utf8           1.1.4     2018-05-24 [1] CRAN (R 3.6.3)
 vctrs          0.2.4     2020-03-10 [1] CRAN (R 3.6.3)
 viridisLite    0.3.0     2018-02-01 [1] CRAN (R 3.6.3)
 withr          2.2.0     2020-04-20 [1] CRAN (R 3.6.3)

[1] C:/Users/Álvaro López/Documents/R/win-library/3.6
[2] C:/Program Files/R/R-3.6.3/library

Sorry to hear you are having problems. I am unfortunately not sure I understand exactly what is happening beyond the fact that your Rtools installation is broken and Stan need RTools. While someone here might be able to help you with RTools issues, it might be more efficient to seek RTools specific help.

Also note that you can use triple backtics (```) to mark code/output in your post to make it more readable (I’ve edited the post for you now).

EDIT one thing that looks suspicious is that maybe the system has problems with spaces in directory names (as your user directory has). Could you try moving your project somewhere with no spaces in path?

Hello,

Thank you very much for your advise regarding spaces in directory. I rebooted the whole computer to its default state so i would be able to change the name of the directory.
After these, i run rstan in R 3.6.3 again according “RStan getting started” and it works.

Yours faithfully.