Trouble Setting up CmdStan in Windows 11

Short summary of the problem

I am trying to model with stan in R but I am running into multiple errors which after a few hours I am at a loss on how to progress. I try installing cmdstan:

install_cmdstan(
  dir = NULL,
  cores = getOption("mc.cores", 2),
  quiet = FALSE,
  overwrite = FALSE,
  timeout = 1200,
  version = NULL,
  release_url = NULL,
  cpp_options = list(),
  check_toolchain = TRUE
)

I then get an error:
Error:
Rtools42 installation found but the toolchain was not installed.
Run cmdstanr::check_cmdstan_toolchain(fix = TRUE) to fix the issue.

I then run the suggested code to try and fix the issue:

cmdstanr::check_cmdstan_toolchain(fix = TRUE)

Installing mingw32-make and g++ with Rtools42.
Error in processx::run("pacman", args = c("-Sy", install_pkgs, "--noconfirm"), …:
! System command ‘pacman’ failed

Exit status: 1
Stderr:
error: failed to synchronize all databases (unable to lock database)

I am not really sure how to proceed or remedy this issue. I tried consulting this post (Trouble with cmdstan toolchain with RTools42 on Windows 10 Enterprise) but was unable to fix the problem.

  • Operating System:
    Windows 11
  • RStan Version:
    2.26.13
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
    Error in file(con, “r”) : cannot open the connection
    In addition: Warning message:
    In file(con, “r”) :
    cannot open file ‘C:/Users/willi/Documents/.R/Makevars’: No such file or directory
  • Output of devtools::session_info("rstan")
    setting value
    version R version 4.2.2 (2022-10-31 ucrt)
    os Windows 10 x64 (build 22000)
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United States.utf8
    ctype English_United States.utf8
    tz America/New_York
    date 2022-12-02
    rstudio 2022.07.1+554 Spotted Wakerobin (desktop)
    pandoc 2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)

I’ve just tried the install on a Windows 11 VM without any issues, so there might some environment/configuration edge case that’s causing issues here.

Can you try running just the mingw32-make installation step and post the output that you get:

install_pkgs <- c("mingw-w64-ucrt-x86_64-make", "mingw-w64-ucrt-x86_64-gcc")
processx::run("pacman", args = c("-Sy", install_pkgs, "--noconfirm"))

Hello,

Thank you so much for your reply. I ran the code and I got the following error.

Error in processx::run("pacman", args = c("-Sy", install_pkgs, "--noconfirm")):
! System command ‘pacman’ failed

Exit status: 1
Stderr:
error: failed to synchronize all databases (unable to lock database)

Backtrace:

  1. processx::run(“pacman”, args = c(“-Sy”, install_pkgs, “–noconfirm”))
  2. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …

I agree that it is most likely on the environment/configuration side but I am a novice in that area.

I am not sure what the overall issue was but I completely uninstalled R and then re-installed it following these directions: How to uninstall R and RStudio with all packages, settings and everything else? - Stack Overflow.

My issue has resolved and I am able to use RStan.

Thank you,

Will