Error in compileCode(), Compilation ERROR, Warning message: In system(cmd, intern = !verbose) , Error in sink(type = "output")

Hello people. I have a giant problem in Rstan that I believe is compiled. Before, the RStan program worked very well, but I don’t know if it was because of an update to the R packages (through Rstudio) that it started to give the problem.

First I will inform the configuration of my system.

sessionInfo()

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252

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

other attached packages:
[1] rstan_2.19.3 ggplot2_3.3.0 StanHeaders_2.21.0-1

loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 pillar_1.4.3 compiler_3.6.2 prettyunits_1.1.1 tools_3.6.2
[6] packrat_0.5.0 pkgbuild_1.0.6 lifecycle_0.2.0 tibble_2.1.3 gtable_0.3.0
[11] pkgconfig_2.0.3 rlang_0.4.5 cli_2.0.2 rstudioapi_0.11 parallel_3.6.2
[16] loo_2.2.0 gridExtra_2.3 withr_2.1.2 dplyr_0.8.5 stats4_3.6.2
[21] grid_3.6.2 tidyselect_0.2.5 glue_1.3.1 inline_0.3.15 R6_2.4.1
[26] processx_3.4.2 fansi_0.4.1 callr_3.4.2 purrr_0.3.2 magrittr_1.5
[31] scales_1.1.0 ps_1.3.2 matrixStats_0.55.0 assertthat_0.2.1 colorspace_1.4-1
[36] munsell_0.5.0 crayon_1.3.4

Now, I will explain how the error occurs. I simply run a model (indicated in RStan Getting Started https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started) and it returns that error. I have already uninstalled R and Rstudio. reinstalled and searched the internet for similar errors but I can’t find a solution. I thank you for your attention.

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Zarzar/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
g++.exe: error: Zarzar/Documents/R/win-library/3.6/StanHeaders/include: No such file or directory
g++.exe: error: Zarzar/Documents/R/win-library/3.6/RcppEigen/include: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: file223c26296dc5.o] Error 1
Além disso: Warning message:
In system(cmd, intern = !verbose) :
execução do comando ‘C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file223c26296dc5.cpp 2> file223c26296dc5.cpp.err.txt’ teve status 1
Error in sink(type = “output”) : conexão inválida

Please I need a very detailed guidance on what to do and how to do it on windows if it is something complicated.

Sincerely Carlos A. Zarzar

If you are going to use R 3.6 on Windows, then you need to install StanHeaders from source via

install.packages("StanHeaders", type = "source")

Yes @bgoodri, I have guaranteed that the package “StanHeaders” was installed. But the same error keeps showing up.

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Zarzar/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
g++.exe: error: Zarzar/Documents/R/win-library/3.6/StanHeaders/include: No such file or directory
g++.exe: error: Zarzar/Documents/R/win-library/3.6/RcppEigen/include: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:215: file216c2f6ab0e.o] Error 1
Além disso: Warning message:
In system(cmd, intern = !verbose) :
execução do comando ‘C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file216c2f6ab0e.cpp 2> file216c2f6ab0e.cpp.err.txt’ teve status 1
Error in sink(type = “output”) : conexão inválida

sessionInfo()

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252

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

other attached packages:
[1] rstan_2.19.3 ggplot2_3.3.0 StanHeaders_2.21.0-1

loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 rstudioapi_0.11 magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0
[6] colorspace_1.4-1 R6_2.4.1 rlang_0.4.5 fansi_0.4.1 dplyr_0.8.5
[11] tools_3.6.2 pkgbuild_1.0.6 parallel_3.6.2 grid_3.6.2 packrat_0.5.0
[16] gtable_0.3.0 loo_2.2.0 cli_2.0.2 withr_2.1.2 matrixStats_0.55.0
[21] assertthat_0.2.1 tibble_2.1.3 lifecycle_0.2.0 crayon_1.3.4 processx_3.4.2
[26] gridExtra_2.3 purrr_0.3.2 callr_3.4.2 ps_1.3.2 inline_0.3.15
[31] glue_1.3.1 compiler_3.6.2 pillar_1.4.3 scales_1.1.0 prettyunits_1.1.1
[36] stats4_3.6.2 pkgconfig_2.0.3

What else do you suggest? have you any idea what it might be?

Thank you very much for your attention.

Ah, you need the StanHeaders that goes with rstan 2.19

install.packages(
"https://cran.r-project.org/src/contrib/StanHeaders_2.19.2.tar.gz",
repos = NULL, type = "source")

Great @bgoodri. Thank you very much for your attention. Solved problem!