Can't compile stan program from R

Operating System: Windows 11
Interface Version: cmdstanr 0.8
Compiler/Toolkit: rtools43

I was trying to create stan model object as follows:

  # create stan model object
  file.copy(file.path(modelDir, paste0(modelName, ".stan")), 
            file.path(outDir, paste0(modelName, ".stan")), overwrite = TRUE)
  mod <- cmdstan_model(file.path(outDir, paste0(modelName, ".stan")))
  fit <- mod$sample(data = data, chains = nChains, init = init,
                    parallel_chains = nChains,
                    iter_warmup = nBurn, iter_sampling = nPost,
                    seed = sample(1:999999, 1), adapt_delta = 0.8,
                    refresh = 10,
                    output_dir = outDir)
  fit$save_object(file.path(outDir, paste0(modelName, ".fit.RDS")))
  fit <- readRDS(file.path(outDir, paste0(modelName, ".fit.RDS")))

And I got the following error:

Compiling Stan program...
Error in `process_initialize(self, private, command, args, stdin, stdout, …`:
! Native call to `processx_exec` failed
Caused by error in `chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …`:
! Command 'bin/stanc.exe' not found @win/processx.c:982 (processx_exec)
Type .Last.error to see the more details.

I have read a lot of these sorts of struggles but none seem to be what I need. Advice is appreciated.

You might want to try cmdstanr, which is much easier to install and keep up to date with Stan than RStan (for reasons having to do with both how RStan’s architected in memory and the restrictive CRAN policies on size and lack of dependency management).

The top-level instructions for installing Rstan are here and they’re very particular:

I would pay particular attention to configuring the C++ toolchain part, as it’s not finding the executable for stanc (the Stan to C++ transpiler). Did you try the verification suggested in the install instructions, which is the following?

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