Failure to run Rstan, Windows 11 R4.4.2

Short summary of the problem:

I can’t get Rstan working. It’s a Windows 11 PC, and I’ve downloaded R 4.4.2, RStudio 2024.09.1 Build 394, and Rtools44. Then, within RStudio, install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies = TRUE)

I’ve then tried:
example(stan_model, package = “rstan”, run.dontrun = TRUE)
This doesn’t work (see error message below).

I also attempted to verify toolchain is okay, by typing:
pkgbuild::check_build_tools(debug = TRUE)
Which returned:
Found in Rtools 4.4 installation folder
Your system is ready to build packages!

Operating System: Windows 11 home 24H2
Interface Version: RStan 2.32.2
Compiler/Toolkit: Er…I guess Rtools 4.4?

Error message from example(stan_model, package = “rstan”, run.dontrun = TRUE):

Error in compileCode(f, code, language = language, verbose = verbose) :
/Users/kiela/AppData/Local/R/win-library/4.4/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp:22:0: required from ‘double stan::mcmc::dense_e_metric<Model, BaseRNG>::T(stan::mcmc::dense_e_point&) [with Model = model4a88429f1e9c__namespace::model4a88429f1e9c_; BaseRNG = boost::random::mixmax_engine<17, 36, 0>]’
C:/Users/kiela/AppData/Local/R/win-library/4.4/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp:21:0: required from here
C:/Users/kiela/AppData/Local/R/win-library/4.4/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:654:74: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits::type’ {aka ‘__m128d’} [-Wignored-attributes]
654 | return internal::first_aligned<int(unpacket_traits::alignment),Derived>(m);
| ^~~~~~~~~
make: *** [C:/PROGRA~1/R/R-44~1.2/etc/x64/Makeconf:296: file4a883a3c6169.o
Error in sink(type = “output”) : invalid connection

I also tried this for diagnostics based on advice I saw somewhere via Google…

devtools::session_info(“rstan”)

Which returned:
─ Session info ────────────────────────────────────────────────────────────────────────
setting value
version R version 4.4.2 (2024-10-31 ucrt)
os Windows 11 x64 (build 26100)
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United Kingdom.utf8
ctype English_United Kingdom.utf8
tz Europe/London
date 2024-12-01
rstudio 2024.09.1+394 Cranberry Hibiscus (desktop)
pandoc NA

─ Packages ────────────────────────────────────────────────────────────────────────────
! package * version date (UTC) lib source
abind 1.4-8 2024-09-12 [1] CRAN (R 4.4.1)
backports 1.5.0 2024-05-23 [1] CRAN (R 4.4.0)
BH 1.84.0-0 2024-01-10 [1] CRAN (R 4.4.0)
callr 3.7.6 2024-03-25 [1] CRAN (R 4.4.2)
checkmate 2.3.2 2024-07-29 [1] CRAN (R 4.4.2)
cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.2)
colorspace 2.1-1 2024-07-26 [1] CRAN (R 4.4.2)
desc 1.4.3 2023-12-10 [1] CRAN (R 4.4.2)
distributional 0.5.0 2024-09-17 [1] CRAN (R 4.4.2)
fansi 1.0.6 2023-12-08 [1] CRAN (R 4.4.2)
farver 2.1.2 2024-05-13 [1] CRAN (R 4.4.2)
generics 0.1.3 2022-07-05 [1] CRAN (R 4.4.2)
ggplot2 3.5.1 2024-04-23 [1] CRAN (R 4.4.2)
glue 1.8.0 2024-09-30 [1] CRAN (R 4.4.2)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.4.2)
gtable 0.3.6 2024-10-25 [1] CRAN (R 4.4.2)
inline 0.3.20 2024-11-10 [1] CRAN (R 4.4.2)
isoband 0.2.7 2022-12-20 [1] CRAN (R 4.4.2)
labeling 0.4.3 2023-08-29 [1] CRAN (R 4.4.0)
lattice 0.22-6 2024-03-20 [2] CRAN (R 4.4.2)
lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.2)
loo 2.8.0.9000 2024-11-25 [1] https://stan-dev.r-universe.dev (R 4.4.2)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.2)
MASS 7.3-61 2024-06-13 [2] CRAN (R 4.4.2)
Matrix 1.7-1 2024-10-18 [2] CRAN (R 4.4.2)
matrixStats 1.4.1 2024-09-08 [1] CRAN (R 4.4.2)
mgcv 1.9-1 2023-12-21 [2] CRAN (R 4.4.2)
munsell 0.5.1 2024-04-01 [1] CRAN (R 4.4.2)
nlme 3.1-166 2024-08-14 [2] CRAN (R 4.4.2)
numDeriv 2016.8-1.1 2019-06-06 [1] CRAN (R 4.4.0)
pillar 1.9.0 2023-03-22 [1] CRAN (R 4.4.2)
pkgbuild 1.4.5 2024-10-28 [1] CRAN (R 4.4.2)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.2)
posterior 1.6.0 2024-11-11 [1] https://stan-dev.r-universe.dev (R 4.4.2)
processx 3.8.4 2024-03-16 [1] CRAN (R 4.4.2)
ps 1.8.1 2024-10-28 [1] CRAN (R 4.4.2)
QuickJSR 1.4.0 2024-10-01 [1] CRAN (R 4.4.2)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.2)
RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.4.0)
Rcpp 1.0.13-1 2024-11-02 [1] CRAN (R 4.4.2)
RcppEigen 0.3.4.0.2 2024-08-24 [1] CRAN (R 4.4.2)
D RcppParallel 5.1.9 2024-08-19 [1] CRAN (R 4.4.2)
rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.2)
rstan * 2.32.6 2024-03-05 [1] CRAN (R 4.4.2)
scales 1.3.0 2023-11-28 [1] CRAN (R 4.4.2)
StanHeaders * 2.35.0.9000 2024-11-24 [1] https://stan-dev.r-universe.dev (R 4.4.2)
tensorA 0.36.2.1 2023-12-13 [1] CRAN (R 4.4.0)
tibble 3.2.1 2023-03-20 [1] CRAN (R 4.4.2)
utf8 1.2.4 2023-10-22 [1] CRAN (R 4.4.2)
vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.2)
viridisLite 0.4.2 2023-05-02 [1] CRAN (R 4.4.2)
withr 3.0.2 2024-10-28 [1] CRAN (R 4.4.2)

[1] C:/Users/kiela/AppData/Local/R/win-library/4.4
[2] C:/Program Files/R/R-4.4.2/library

D ── DLL MD5 mismatch, broken installation.

After that I tried to fix the mismatch in case that was the problem, but it didn’t work:

install.packages(“RcppParallel”, type = “source”, dependencies = TRUE)

Installing package into ‘C:/Users/kiela/AppData/Local/R/win-library/4.4’
(as ‘lib’ is unspecified)
trying URL ‘https://cran.rstudio.com/src/contrib/RcppParallel_5.1.9.tar.gz
Content type ‘application/x-gzip’ length 1632664 bytes (1.6 MB)
downloaded 1.6 MB

  • installing source package ‘RcppParallel’ …
    ** package ‘RcppParallel’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** preparing to configure package ‘RcppParallel’ …
    *** configured file: ‘R/tbb-autodetected.R.in’ => ‘R/tbb-autodetected.R’
    *** configured file: ‘src/Makevars.in’ => ‘src/Makevars’
    *** configured file: ‘src/install.libs.R.in’ => ‘src/install.libs.R’
    ** finished configure for package ‘RcppParallel’
    ** libs
    using C++ compiler: ‘G__~1.EXE (GCC) 13.3.0’
    (tbb) Building TBB using bundled sources …
    make[1]: Entering directory ‘/c/Users/kiela/AppData/Local/Temp/RtmpcZRQgP/R.INSTALL33781363374c/RcppParallel/src/tbb/src’
    OS: windows
    arch=intel64
    compiler=gcc
    runtime=mingw
    tbb_build_prefix=windows_intel64_gcc_mingw
    work_dir=/c/Users/kiela/AppData/Local/Temp/RtmpcZRQgP/R.INSTALL33781363374c/RcppParallel/src/build/windows_intel64_gcc_mingw_release
    make[1]: Leaving directory ‘/c/Users/kiela/AppData/Local/Temp/RtmpcZRQgP/R.INSTALL33781363374c/RcppParallel/src/tbb/src’
    (tbb) TBB compilation finished successfully.
    g++ -std=gnu++17 -I"C:/PROGRA~1/R/R-44~1.2/include" -DNDEBUG -I…/inst/include -I"C:/rtools44/x86_64-w64-mingw32.static.posix/include" -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c init.cpp -o init.o
    g++ -std=gnu++17 -I"C:/PROGRA~1/R/R-44~1.2/include" -DNDEBUG -I…/inst/include -I"C:/rtools44/x86_64-w64-mingw32.static.posix/include" -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c options.cpp -o options.o
    g++ -std=gnu++17 -shared -s -static-libgcc -o RcppParallel.dll tmp.def init.o options.o C:/Users/kiela/AppData/Local/R/win-library/4.4/rstan/lib/x64/libStanServices.a -LC:/Users/kiela/AppData/Local/R/win-library/4.4/StanHeaders/libs/x64 -lStanHeaders -LC:/Users/kiela/AppData/Local/R/win-library/4.4/RcppParallel/lib/x64 -ltbb -LC:/Users/kiela/AppData/Local/R/win-library/4.4/RcppParallel/lib/x64 -ltbb -ltbbmalloc -LC:/rtools44/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/rtools44/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-44~1.2/bin/x64 -lR
    C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -ltbb: No such file or directory
    C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -ltbb: No such file or directory
    collect2.exe: error: ld returned 1 exit status
    installing via ‘install.libs.R’ to C:/Users/kiela/AppData/Local/R/win-library/4.4/00LOCK-RcppParallel/00new/RcppParallel
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    Error: package or namespace load failed for ‘RcppParallel’:
    .onLoad failed in loadNamespace() for ‘RcppParallel’, details:
    call: library.dynam(“RcppParallel”, pkgname, libname)
    error: DLL ‘RcppParallel’ not found: maybe not installed for this architecture?
    Error: loading failed
    Execution halted
    ERROR: loading failed
  • removing ‘C:/Users/kiela/AppData/Local/R/win-library/4.4/RcppParallel’
  • restoring previous ‘C:/Users/kiela/AppData/Local/R/win-library/4.4/RcppParallel’
    Warning in install.packages :
    installation of package ‘RcppParallel’ had non-zero exit status

The downloaded source packages are in
‘C:\Users\kiela\AppData\Local\Temp\RtmpEJyY7x\downloaded_packages’