# Errors compiling first stan model in R

**URL:** <https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151>\
**Category:** Interfaces\
**Created:** [May 14, 2024, 12:27pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151 "2024-05-14T12:27:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin.OPella](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Justin.OPella](https://discourse.mc-stan.org/u/Justin.OPella)\
**Post date:** [May 14, 2024, 12:27pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/1 "2024-05-14T12:27:58Z")

</div>

Hi, I have been going through the Statistical Rethinking book and am at the MCMC portion of the book and went to execute the code (partially shown) and am met with the following message.

```no-highlight
m9.1 <- ulam(
     alist(
         log_gdp_std ~ dnorm( mu , sigma ) ,
         mu <- a[cid] + b[cid]*( rugged_std - 0.215 ) ,
         a[cid] ~ dnorm( 1 , 0.1 ) ,
         b[cid] ~ dnorm( 0 , 0.3 ) ,
         sigma ~ dexp( 1 )
     ) , data=dat_slim , chains=1 )

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, …`:
! cannot start processx process 'bin/stanc' (system error 2, No such file or directory) @unix/processx.c:613 (processx_exec)
Type .Last.error to see the more details.

```

I apologize if this is a common error but I have been unable to fix it. I am in R (latest version) and on a MacOS Sonoma. From what I can tell, I have the necessary tools on my machine (xcode, gcc, clang) though this piece is not my expertise so forgive me if this does not make a ton of sense. I have read a bunch of stuff online the last few days that mentions this part is often the most frustrating so I am hoping for some feedback or push in the right direction so that I can execute the code and make use of Stan in R. Any help is appreciated.

Thank you

[edit: escaped code]

---

<div class="post-metadata">

**Author:** ![Justin.OPella](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Justin.OPella](https://discourse.mc-stan.org/u/Justin.OPella)\
**Post date:** [May 14, 2024, 9:08pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/2 "2024-05-14T21:08:31Z")

</div>

not sure if this helps explain the issue better but here are my checks in R:

> macrtools::is\_xcode\_cli\_installed()  
> [1] FALSE  
> macrtools::is\_gfortran\_installed()  
> [1] TRUE  
> macrtools::is\_xcode\_app\_installed()  
> [1] TRUE

which tells me (i think) to install x code by entering xcode-select --install in a terminal, which gives me the response below…I will keep trying things out but wanted to post this in case anyone has an idea that I am missing. Both my Xcode and R are up to date. Thanks

xcode-select: note: Command line tools are already installed. Use “Software Update” in System Settings or the softwareupdate command line interface to install updates

---

<div class="post-metadata">

**Author:** ![Justin.OPella](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Justin.OPella](https://discourse.mc-stan.org/u/Justin.OPella)\
**Post date:** [May 16, 2024, 12:29pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/3 "2024-05-16T12:29:31Z")

</div>

Hi all,  
Adding some more details. Some other things I have tried…when I uninstall the xcode app, then enter macrtools:: is\_xcode\_installed() the response changes to TRUE but then when I put the xcode app back in, the response changes to FALSE. I’ve gone through and both my cmdstanr and rstan folders seem to be in the right directory. I have also made sure permissions were changed from ‘read’ to ‘read and write’ but still experiencing the issue. Below is the expanded error message. Any ideas? Hoping to try on a different machine this weekend to see if I have any better results but hoping maybe someone sees something I don’t.  
Thanks

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, …`:  
! cannot start processx process ‘bin/stanc’ (system error 2, No such file or directory) @unix/processx.c:613 (processx\_exec)  
Type .Last.error to see the more details.

> .Last.error  
> \<c\_error/rlib\_error\_3\_0/rlib\_error/error\>  
> 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, …`:  
> ! cannot start processx process ‘bin/stanc’ (system error 2, No such file or directory) @unix/processx.c:613 (processx\_exec)

* * *

Backtrace:

1. rethinking::ulam(alist(log\_gdp\_std ~ dnorm(mu, sigma), mu ← a[cid] + b[cid] \* …
2. cmdstanr::cmdstan\_model(stan\_file = filex[[1]], compile = filex[[3]], cpp\_options = cpp\_options, …
3. CmdStanModel$new(stan\_file = stan\_file, exe\_file = exe\_file, …
4. local initialize(…)
5. self$compile(…)
6. cmdstanr:::get\_standalone\_hpp(temp\_stan\_file, stancflags\_standalone)
7. withr::with\_path(c(toolchain\_PATH\_env\_var(), tbb\_path()), wsl\_compatible\_run(command = stanc\_cmd(), …
8. base::force(code)
9. cmdstanr:::wsl\_compatible\_run(command = stanc\_cmd(), args = c(paste0(“–o=”, …
10. base::do.call(processx::run, run\_args)
11. (function (command = NULL, args = character(), error\_on\_status = TRUE, …
12. process$new(command, args, echo\_cmd = echo\_cmd, wd = wd, windows\_verbatim\_args = windows\_verbatim\_args, …
13. local initialize(…)
14. processx:::process\_initialize(self, private, command, args, stdin, stdout, …
15. processx:::chain\_call(c\_processx\_exec, command, c(command, args), pty, pty\_options, …
16. | base::withCallingHandlers(do.call(“.Call”, list(.NAME, …)), error = function(e) { …
17. | base::do.call(“.Call”, list(.NAME, …))
18. | base::.handleSimpleError(function (e) …
19. | local h(simpleError(msg, call))
20. | processx:::throw\_error(err, parent = e)

---

<div class="post-metadata">

**Author:** ![Justin.OPella](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Justin.OPella](https://discourse.mc-stan.org/u/Justin.OPella)\
**Post date:** [May 16, 2024, 12:36pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/4 "2024-05-16T12:36:54Z")

</div>

other things I am _hoping_ help bring some clarity:

1. when I enter cmdstan\_path() in R, I receive the correct path where the package is located
2. when I enter stanc\_path() in R, I receive: Error in stanc\_path() : could not find function “stanc\_path”
3. when I enter get\_stan\_version() in R, I receive: Error in get\_stan\_version() : could not find function “get\_stan\_version”

Does this help explain the issue? Sorry if I am overlooking something simple or this is more a problem with my device and not Stan

---

<div class="post-metadata">

**Author:** ![Kirsty\_Hawkins](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kirsty_hawkins/32/19952_2.png) [@Kirsty\_Hawkins](https://discourse.mc-stan.org/u/Kirsty_Hawkins)\
**Post date:** [January 27, 2025, 5:41pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/5 "2025-01-27T17:41:14Z")

</div>

Did you ever get a resolution to this error? I am facing the same one and I can’t work out what’s going on

---

<div class="post-metadata">

**Author:** ![Justin.OPella](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Justin.OPella](https://discourse.mc-stan.org/u/Justin.OPella)\
**Post date:** [January 27, 2025, 6:08pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/6 "2025-01-27T18:08:59Z")

</div>

No, I did not, unfortunately. My work around was that I could run programs from the terminal in Stan (not the stan package in R). The challenge here is that the Stan language is more complex than the stan language used in R so I would write the code in R then use a tool like ChatGPT to convert it to pure Stan language.

Not sure if that helps but that was my experience. I tried so many other things and got no where. Good luck!

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [January 27, 2025, 9:24pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/7 "2025-01-27T21:24:14Z")

</div>

Do you have Rosetta installed? This will be relaxed in the next release, but currently running the stanc compiler requires Rosetta on the newer macs

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [January 27, 2025, 9:45pm UTC](https://discourse.mc-stan.org/t/errors-compiling-first-stan-model-in-r/35151/8 "2025-01-27T21:45:39Z")

</div>

> [@Justin.OPella](#):
>
> The challenge here is that the Stan language is more complex than the stan language used in R

There’s only one

Stan language. Do you mean the expression syntax we have in `brms`? That’s a higher-level language following R’s `lme4` package, but it isn’t the Stan language per se.

> [@Justin.OPella](#):
>
> so I would write the code in R then use a tool like ChatGPT to convert it to pure Stan language.

If you’re writing the model in `brms`, you can get the Stan model for that directly from `brms`.

> [@Justin.OPella](#):
>
> My work around was that I could run programs from the terminal in Stan (not the stan package in R).

If you mean you could run `CmdStan`, then it should be easy to install `cmdstanr`, which is relatively straightforward to install once you have a working version of `CmdStan`.
