Brm() and RStan won't compile since upgrade to R 4.2.2 and Rtools42; Help!

Hello all,

Since upgrading to R 4.2.2 and Rtools42 I haven’t been able to get brms (or Stan) to work. Ack. I’m definitely short a few hairs since starting. I’m hoping with your help I can find a way to resolve the problem without having to resort to the nuclear option of uninstalling/reinstalling R etc.

So far I’ve upgraded the C++ toolchain for 4.2 as described at :

Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub and
Stan & R 4.2 on Windows – The Stan Blog

But when I run example(stan_model,run.dontrun=T), I end up with the same error message at the end of a pile of code (omitted top 423 lines–please let me know if you’d like to see them!). Here is the gist of the errors:

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

Program source:
  1: 
  2: // includes from the plugin
  3: // [[Rcpp::plugins(cpp14)]]
  4: 
  5: 
  6: // user includes
  7: #include <Rcpp.h>
  8: using namespace Rcpp;
  9: #ifndef MODELS_HPP
 10: #define MODELS_HPP
 11: #define STAN__SERVICES__COMMAND_HPP
 12: #include <rstan/rstaninc.hpp>
 13: #ifndef USE_STANC3
 14: #define USE_STANC3
 15: #endif

…and the final error:

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  g++.exe: error: x86_64: No such file or directoryg++.exe: error: unrecognized command-line option '-arch'make: *** [C:/PROGRA~1/R/R-42~1.2/etc/x64/Makeconf:260: file17dc17416ba0.o] Error 1

Here is some additional info:

> Sys.getenv("PATH")
[1] "C:\\rtools42\\usr\\bin;C:\\rtools42\\x86_64-w64-mingw32.static.posix\\bin;C:\\rtools42\\usr\\bin;C:\\rtools42\\usr\\bin;C:\\Program Files\\R\\R-4.2.2\\bin\\x64;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath_target_634954671;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Windows\\System32;C:\\Windows;C:\\Windows\\System32\\wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0;C:\\Windows\\System32\\OpenSSH;C:\\Program Files\\dotnet;D:\\Git\\cmd;C:\\ProgramData\\chocolatey\\bin;;C:\\Program Files\\Docker\\Docker\\resources\\bin;C:\\Users\\shaun\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\shaun\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\shaun\\AppData\\Local\\Pandoc;C:\\Users\\shaun\\AppData\\Local\\gitkraken\\bin;C:\\Users\\shaun\\AppData\\Roaming\\TinyTeX\\bin\\win32;;C:\\Program Files\\RStudio\\resources\\app\\bin\\quarto\\bin;C:\\Program Files\\RStudio\\resources\\app\\bin\\rpostback;C:\\Program Files\\RStudio\\resources\\app\\bin\\postback"

The path looks insanely messy imho–though I’m not sure how to remedy this or if it is even a problem.

>Sys.getenv("BINPREF")
[1] ""

>readLines("~/.Rprofile")

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'D:/documents/.Rprofile': No such file or directory

^^ The .Rprofile file was deleted when trying to move back to Rtools 40 at one point (it’s been a journey!)

> writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14FLAGS += -O3 -mtune=native -arch x86_64 -ftemplate-depth-256

^^ the error message I get when compiling the test model mentions the -arch as an ‘unrecognized command-line option’. Maybe a problem with Makevars config?

> readLines("~/.Renviron")
[1] "PATH=\"${RTOOLS42_HOME}\\usr\\bin;${PATH}\""
devtools::session_info("rstan")
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.2 (2022-10-31 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_Canada.utf8
 ctype    English_Canada.utf8
 tz       America/New_York
 date     2022-12-20
 rstudio  2022.12.0+353 Elsbeth Geranium (desktop)
 pandoc   2.19.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package      * version   date (UTC) lib source
 backports      1.4.1     2021-12-13 [1] CRAN (R 4.2.0)
 BH             1.78.0-0  2021-12-15 [1] CRAN (R 4.2.0)
 callr          3.7.3     2022-11-02 [1] CRAN (R 4.2.2)
 checkmate      2.1.0     2022-04-21 [1] CRAN (R 4.2.2)
 cli            3.4.1     2022-09-23 [1] CRAN (R 4.2.2)
 colorspace     2.0-3     2022-02-21 [1] CRAN (R 4.2.2)
 crayon         1.5.2     2022-09-29 [1] CRAN (R 4.2.2)
 curl           4.3.3     2022-10-06 [1] CRAN (R 4.2.2)
 desc           1.4.2     2022-09-08 [1] CRAN (R 4.2.2)
 fansi          1.0.3     2022-03-24 [1] CRAN (R 4.2.2)
 farver         2.1.1     2022-07-06 [1] CRAN (R 4.2.2)
 ggplot2      * 3.4.0     2022-11-04 [1] CRAN (R 4.2.2)
 glue           1.6.2     2022-02-24 [1] CRAN (R 4.2.2)
 gridExtra      2.3       2017-09-09 [1] CRAN (R 4.2.2)
 gtable         0.3.1     2022-09-01 [1] CRAN (R 4.2.2)
 inline         0.3.19    2021-05-31 [1] CRAN (R 4.2.2)
 isoband        0.2.6     2022-10-06 [1] CRAN (R 4.2.2)
 jsonlite       1.8.4     2022-12-06 [1] CRAN (R 4.2.2)
 labeling       0.4.2     2020-10-20 [1] CRAN (R 4.2.0)
 lattice        0.20-45   2021-09-22 [1] CRAN (R 4.2.2)
 lifecycle      1.0.3     2022-10-07 [1] CRAN (R 4.2.2)
 loo            2.5.1     2022-03-24 [1] CRAN (R 4.2.2)
 magrittr       2.0.3     2022-03-30 [1] CRAN (R 4.2.2)
 MASS           7.3-58.1  2022-08-03 [1] CRAN (R 4.2.2)
 Matrix       * 1.5-3     2022-11-11 [1] CRAN (R 4.2.2)
 matrixStats    0.63.0    2022-11-18 [1] CRAN (R 4.2.2)
 mgcv         * 1.8-41    2022-10-21 [1] CRAN (R 4.2.2)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 4.2.2)
 nlme         * 3.1-161   2022-12-15 [1] CRAN (R 4.2.2)
 pillar         1.8.1     2022-08-19 [1] CRAN (R 4.2.2)
 pkgbuild       1.4.0     2022-11-27 [1] CRAN (R 4.2.2)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.2.2)
 prettyunits    1.1.1     2020-01-24 [1] CRAN (R 4.2.2)
 processx       3.8.0     2022-10-26 [1] CRAN (R 4.2.2)
 ps             1.7.2     2022-10-26 [1] CRAN (R 4.2.2)
 R6             2.5.1     2021-08-19 [1] CRAN (R 4.2.2)
 RColorBrewer   1.1-3     2022-04-03 [1] CRAN (R 4.2.0)
 Rcpp         * 1.0.9     2022-07-08 [1] CRAN (R 4.2.2)
 RcppEigen      0.3.3.9.3 2022-11-05 [1] CRAN (R 4.2.2)
 RcppParallel   5.1.5     2022-01-05 [1] CRAN (R 4.2.2)
 rlang          1.0.6     2022-09-24 [1] CRAN (R 4.2.2)
 rprojroot      2.0.3     2022-04-02 [1] CRAN (R 4.2.2)
 rstan        * 2.26.13   2022-06-25 [1] local
 scales         1.2.1     2022-08-20 [1] CRAN (R 4.2.2)
 StanHeaders  * 2.26.13   2022-06-25 [1] local
 tibble       * 3.1.8     2022-07-22 [1] CRAN (R 4.2.2)
 utf8           1.2.2     2021-07-24 [1] CRAN (R 4.2.2)
 V8             4.2.2     2022-11-03 [1] CRAN (R 4.2.2)
 vctrs          0.5.1     2022-11-16 [1] CRAN (R 4.2.2)
 viridisLite    0.4.1     2022-08-22 [1] CRAN (R 4.2.2)
 withr          2.5.0     2022-03-03 [1] CRAN (R 4.2.2)

 [1] D:/documents/ConspiracyProject/renv/library/R-4.2/x86_64-w64-mingw32
 [2] C:/Users/shaun/AppData/Local/Temp/RtmpWaDRTQ/renv-system-library

I’m thinking this has to do with a communication problem between R and C? Maybe a problem with renv? Anyhow, I’ll leave it there for now. Btw, this is my first time requesting help so huge apologies if I missed something or formatted things incorrectly! Your help is SUPER appreciated :) Thank you!

Shauna

You’ve followed the MacOS steps for confguring your toolchain.

Follow the Windows steps for configuring the Makevars here: Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub

1 Like

Ahhh this worked :) I tried rolling back to old configurations multiple times; I must have clicked on the mac version by accident during one of my many visits. When I googled the -arch issue I kept seeing mention of the Mac OS so I had a feeling something must have been configured wrong! Thanks so much for the help and happy holidays!

Shauna