Building r package using rstan

I tried to follow the “Step by step guide for creating a package that depends on RStan” at Step by step guide for creating a package that depends on RStan • rstantools but got an error message at the end. The bare minimal package failed to compile. The system specs are: Windows 11 Home, R 4.2.2, RStudio 2022.12.0 Build 353, rtools42, rstan 2.21.8, rstantools 2.2.0, StanHeaders 2.21.0-7.

C:\Users\kaife\AppData\Local\Temp\ccGrwRVD.s: Assembler messages:
C:\Users\kaife\AppData\Local\Temp\ccGrwRVD.s: Fatal error: can’t write 87 bytes to section .text of stanExports_lm.o: ‘file too big’
as: stanExports_lm.o: too many sections (36627)
C:\Users\kaife\AppData\Local\Temp\ccGrwRVD.s: Fatal error: stanExports_lm.o: file too big
make: *** [C:/PROGRA~1/R/R-42~1.2/etc/x64/Makeconf:258: stanExports_lm.o] Error 1
ERROR: compilation failed for package ‘rstanlm’
─ removing ‘C:/Users/kaife/AppData/Local/Temp/RtmpmovtZY/devtools_install_129c1b79144d/rstanlm’
Error in (function (command = NULL, args = character(), error_on_status = TRUE, …:
! System command ‘Rcmd.exe’ failed

Exit status: 1
stdout & stderr:

Type .Last.error to see the more details.

.Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in (function (command = NULL, args = character(), error_on_status = TRUE, …:
! System command ‘Rcmd.exe’ failed


Exit status: 1
stdout & stderr:

Backtrace:

  1. roxygen2::roxygenize()
  2. local load_code(base_path)
  3. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
  4. pkgbuild::compile_dll(path, quiet = quiet)
  5. pkgbuild:::install_min(path, dest = install_dir, components = “libs”, args = if (needs_clea…
  6. pkgbuild::rcmd_build_tools(“INSTALL”, c(path, paste(“–library=”, dest, …
  7. pkgbuild::with_build_tools({ …
  8. withr::with_path(rtools_path(), code)
  9. base::force(code)
  10. base::withCallingHandlers(callr::rcmd_safe(…, env = env, spinner = FALSE, …
  11. callr::rcmd_safe(…, env = env, spinner = FALSE, show = FALSE, …
  12. callr:::run_r(options)
  13. base::with(options, with_envvar(env, do.call(processx::run, c(list(bin, …
  14. base::with.default(options, with_envvar(env, do.call(processx::run, …
  15. base::eval(substitute(expr), data, enclos = parent.frame())
  16. base::eval(substitute(expr), data, enclos = parent.frame())
  17. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs, …
  18. base::force(code)
  19. base::do.call(processx::run, c(list(bin, args = real_cmdargs, stdout_line_callback = r…
  20. (function (command = NULL, args = character(), error_on_status = TRUE, …
  21. base::throw(new_process_error(res, call = sys.call(), echo = echo, …
  22. | base::signalCondition(cond)
  23. (function (e) …
  24. asNamespace(“callr”)$err$throw(e)

Any insights are greatly appreciated!

Would suggest avoiding the rstan dependency if possible, not being updated so package maintenance is a hassle. cmdstanr might work for you?

Thanks for the suggestion. I will look into cmdstanr and let you know if it works.

I have tried to install CmdStan and received a warning message. I am not sure how to proceed. Thanks.

Warning in install.packages :
package ‘CmdStan’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at

Charles was referring to cmdstanr with an r at the end. See the website here

When developing the r package on windows, depending on rstan, I met the same problem. I switched to Mac, and then all problems disappeared. Maybe you can have a try on Mac.