Compilation problem since installing rstan 2.19.2 in Windows 10

Would appreciate any advice on fixing the following issue.

The following code to simulate some data work fine in a Windows 8.1 machine runnig R 3.5.3 but ran into compliation errors in a Windows 10 machine running R 3.5.1. In both machines, the rstan and StanHeaders installed are the same: 2.19.2 and 2.19.0, repsectively.

simu_fit <- stan(file = SimFile,   
                 data=PREDdata, 
                 iter=1, 
                 chains=1, 
                 algorithm="Fixed_param")

The following are the compilation errors:

Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! Warning message: In system(cmd) : 'make' not found
9.
stop(paste("Compilation ERROR, function(s)/method(s) not created!", paste(errmsg, collapse = "\n")))
8.
compileCode(f, code, language = language, verbose = verbose)
7.
cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, settings = settings, ..., verbose = verbose)
6.
force(code)
5.
withr::with_path(rtools_path(), code)
4.
pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, settings = settings, ..., verbose = verbose), required = rstan_options("required") && !identical(Sys.getenv("WINDOWS"), "TRUE") && !identical(Sys.getenv("R_PACKAGE_SOURCE"), ...
3.
cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"", model_name, "\");", sep = ""), includes = inc, plugin = "rstan", save_dso = save_dso | auto_write, module_name = paste("stan_fit4", model_cppname, "_mod", sep = ""), verbose = verbose)
2.
stan_model(file, model_name = model_name, model_code = model_code, stanc_ret = NULL, boost_lib = boost_lib, eigen_lib = eigen_lib, save_dso = save_dso, verbose = verbose)
1.
stan(file = SimFile, data = PREDdata, iter = 1, chains = 1, algorithm = "Fixed_param")

Also, a second error:

Error in sink(type = "output") : invalid connection
4.
sink(type = "output")
3.
cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"", model_name, "\");", sep = ""), includes = inc, plugin = "rstan", save_dso = save_dso | auto_write, module_name = paste("stan_fit4", model_cppname, "_mod", sep = ""), verbose = verbose)
2.
stan_model(file, model_name = model_name, model_code = model_code, stanc_ret = NULL, boost_lib = boost_lib, eigen_lib = eigen_lib, save_dso = save_dso, verbose = verbose)
1.
stan(file = SimFile, data = PREDdata, iter = 1, chains = 1, algorithm = "Fixed_param")

Because the first error above said: In system(cmd) : 'make' not found, I reinstalled Rtools 3.5 but this does not fix the problem. The Makevars.win file is the same as on https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows . Also, tried the version below that works in the WIndows 8.1 machine but could not fix the issue:

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y
CXX11FLAGS=-O3 -Wno-unused-variable -Wno-unused-function

Session info:

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

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

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

other attached packages:
[1] rstan_2.19.2       ggplot2_3.2.1      StanHeaders_2.19.0 bayesplot_1.7.0    qs_0.19.1         
[6] stringr_1.4.0      magrittr_1.5       dplyr_0.8.3        here_0.1          

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3          pillar_1.4.2        compiler_3.5.1      plyr_1.8.4          prettyunits_1.0.2  
 [6] tools_3.5.1         pkgbuild_1.0.6      packrat_0.5.0       tibble_2.1.3        gtable_0.3.0       
[11] pkgconfig_2.0.3     rlang_0.4.1         cli_1.1.0           rstudioapi_0.10     parallel_3.5.1     
[16] yaml_2.2.0          xfun_0.10           loo_2.1.0           gridExtra_2.3       withr_2.1.2        
[21] knitr_1.25          stats4_3.5.1        rprojroot_1.3-2     grid_3.5.1          tidyselect_0.2.5   
[26] glue_1.3.1          inline_0.3.15       RApiSerialize_0.1.0 R6_2.4.0            processx_3.4.1     
[31] callr_3.3.2         purrr_0.3.3         matrixStats_0.55.0  ps_1.3.0            backports_1.1.5    
[36] scales_1.0.0        ggridges_0.5.1      assertthat_0.2.1    colorspace_1.4-1    stringi_1.4.3      
[41] lazyeval_0.2.2      munsell_0.5.0       crayon_1.3.4       


[1] "Sat Nov 09 21:10:18 2019"

Try

example(stan_model, package = "rstan", run.dontrun = TRUE)

and tell us the line that has error: in it (with the colon).

Thanks for your reply. Not entirely sure exactly which lines you have in mind. Try copying the following here. Please find the full output here: fullOutput.txt (35.9 KB). Look forward to your further suggestions.

  82 :             // validate, set parameter ranges
  83 :             num_params_r__ = 0U;
  84 :             param_ranges_i__.clear();
  85 :             current_statement_begin__ = 1;
  86 :             num_params_r__ += 1;
  87 :         } catch (const std::exception& e) {
  88 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
  89 :             // Next line prevents compiler griping about no return
  90 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
  91 :         }
  92 :     }
 108 :         current_statement_begin__ = 1;
 109 :         if (!(context__.contains_r("y")))
 110 :             stan::lang::rethrow_located(std::runtime_error(std::string("Variable y missing")), current_statement_begin__, prog_reader__());
 111 :         vals_r__ = context__.vals_r("y");
 112 :         pos__ = 0U;
 113 :         context__.validate_dims("parameter initialization", "y", "double", context__.to_vec());
 114 :         double y(0);
 115 :         y = vals_r__[pos__++];
 116 :         try {
 117 :             writer__.scalar_unconstrain(y);
 118 :         } catch (const std::exception& e) {
 119 :             stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable y: ") + e.what()), current_statement_begin__, prog_reader__());
 120 :         }
167 :         } catch (const std::exception& e) {
 168 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 169 :             // Next line prevents compiler griping about no return
 170 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 171 :         }
 231 :         try {
 232 :             if (!include_gqs__ && !include_tparams__) return;
 233 :             if (!include_gqs__) return;
 234 :         } catch (const std::exception& e) {
 235 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 236 :             // Next line prevents compiler griping about no return
 237 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 238 :         }

ERROR(s) during compilation: source code errors or compiler configuration errors!

Then basically repeated again the lines with error above, followed by the below:

Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! Warning message: In system(cmd) : 'make' not found

That one. It cannot find your RTools. What does

pkgbuild::has_build_tools(TRUE)

say?

Thanks for your reply. It just said:

[1] TRUE

I have Rtools 3.5 installed and have the impression that it is working for other packages that compile from source.

After some search on the internet, apparently the issue is due to not having the path of Rtools in the PATH environment variable (whereas in my another pc with Windows 8.1, C:\\Rtools\\bin;c:\\Rtools\\mingw_64\\bin is in the PATH).

I do not have the Rtools included in the PATH for my Windows 10 machine because during the recent reinstallation, this was unchecked by default (with the warning that it is not recommended). Perhaps, this alone would not cause the problem but previously I also had a testing version of R 3.6 installed, which required RTools 4. Although it is also not in the PATH variable, pkgbuild::rtools_path() gives:

[1] "C:/rtools40/bin"

If no longer bother with the testing version of R 3.6, do you think the easiest fix is just to include C:\\Rtools\\bin;c:\\Rtools\\mingw_64\\bin is in the PATH?

What does

pkgbuild::with_build_tools(Sys.which("make"))

say?

It returns

make
""

Not good. What is

pkgbuild::with_build_tools(Sys.getenv("PATH"))

?

[1] "C:\\rtools40\\bin;C:\\ProgramData\\Anaconda3;C:\\Program Files\\R\\R-3.5.1\\bin\\x64;C:\\ProgramData\\DockerDesktop\\version-bin;C:\\Program Files\\Docker\\Docker\\Resources\\bin;C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2019.1.144\\windows\\mpi\\intel64\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Unified Messaging Client;C:\\Program Files (x86)\\Common Files\\EricssonShare;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C:\\Program Files\\nodejs\\;C:\\Program Files (x86)\\LyX 2.3\\Perl\\bin;C:\\Program Files (x86)\\GnuPG\\bin;C:\\Program Files\\PuTTY\\;C:\\Strawberry\\c\\bin;C:\\Strawberry\\perl\\site\\bin;C:\\Strawberry\\perl\\bin;C:\\Program Files (x86)\\Pandoc\\;C:\\Program Files (x86)\\Mitel\\MiCC Enterprise\\Applications\\Bin;C:\\Program Files (x86)\\Common Files\\EricssonShare\\NextCCShare;C:\\Program Files (x86)\\Mitel\\MiCC Enterprise\\ScriptManager\\Bin;C:\\Program Files (x86)\\Mitel\\MiCC Enterprise\\ScriptManager\\Bin\\ThirdParty;C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin;C:\\Program Files\\dotnet\\;D:\\MATLAB\\R2019a\\bin;D:\\anaconda3\\pkgs\\openssl-1.1.1b-he774522_1\\Library\\bin;C:\\Users\\sbbg070\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\sbbg070\\AppData\\Roaming\\npm"

Does that mean I should uninstall / reinstall RTools 4?

You should not have rtools40 unless you are testing R for Windows 3.7, which won’t be released until April. If you are using R 3.7, then it should work. For R 3.6, 3.5, etc., you need rtools35.

1 Like

The compilation is working again after uninstalling RTools 4.

Thanks so much for your advice.