I’m getting ready to update my MacOS operating system from Sierra 10.12.6 to either Catalina or Mojave. As of right now (November 2020), which update should I expect to give me fewer problems with the Stan family of programs? I’m mainly using Stan through 1) rstanarm, 2) rethinking package, and 3) brms package. Is there even a difference now, meaning have pretty much all of the OS-related issues been seen and solved for these two OSs? I’m considering these two as my options because I’m not nearly adventurous enough to try Big Sur! Hardware is MacBook Pro (15-inch, 2017). Thanks.
I would suggest Catalina instead of Mojave. I’ve been using Catalina for a while now and all of the packages you mentioned work fine. When Catalina first came out there were issues and it was easier to get RStan (which you need for the packages you listed) to work with Mojave, but now the issues with Catalina have either been fixed or we have workarounds, and I think it’s now harder to get things working with the older Mojave (not impossible but not as straightforward).
I’m confident that if you upgrade to Catalina (and the latest version of R) either things will work easily or we’ll be able to help you get it working.
Both cmdstanr and rstan work well (also installation is smooth) for Catalina 10.15.7 from my experience.
Excellent. Thank you, I’ll upgrade to Catalina. Side note: I’ve been watching your sessions on Basics from StanCon 2018 yesterday and today. Good stuff.
Hmm. This page https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-a-Mac says:
We recommend using the macOS R toolchain installer for pre-Catalina versions of the operating system, in which case you can then install the binary version of the RStan package. If you have Catalina , then you need to open it by pressing CTRL+right-click and then clicking Open in order to bypass the security settings that took effect on Macs with Catalina on January 1, 2020.
The way I read that paragraph is that to install on Catalina I need to CTRL+right-click on something, but what is this something? What is the ‘it’ that I need to open? The first sentence says to use the macOS R toolchain installer for pre-Catalina OSs, but doesn’t say what to use for Catalina. The way that paragraph is written specifically excludes the macOS R toolchain installer from being the thing to install, but I don’t see another option, thus my confusion. Thanks.
I see the link is installing rstan from sources. Is this your aim? If you just want to install rstan on Mac, maybe you can directly follow this link https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started ? By running
remove.packages("rstan") if (file.exists(".RData")) file.remove(".RData") ## Then, restart R. (<<---- I didn't restart R....) install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
Thanks, songpeng. That’s the link I start with, but that RStan-Getting-Started page says this, before those commands you quote:
“Prior to installing RStan, you need to configure your R installation to be able to compile C++ code. Follow the link below for your respective operating system for more instructions:”
which then has a link to this page:
Mac - Configuring C++ Toolchain
And that page is the page where I’m confused about what to do. I can’t run the commands you quote until I’ve correctly followed the procedures to install the Toolchain. That’s where I’m stuck.
@bgoodri Can you clarify this and update the RStan pages as necessary? I understand @MichiganWater’s confusion here. The link on the Getting Started page for Mac - Configuring C++ Toolchain takes you to a page that says “Installing RStan from source on a Mac”, but I don’t think it’s just for installing from source, right? That title seems wrong, or am I wrong?
Then, on that page it also says the following, which seems to contradict itself:
We recommend using the macOS R toolchain installer for pre-Catalina versions of the operating system, in which case you can then install the binary version of the RStan package. If you have Catalina, then you need to open it by pressing CTRL+right-click …
This seems to say to only use the R toolchain installer for pre-Catalina but then the next sentence talks about opening it in Catalina. So I’m not sure what it’s intending to say. It also seems to imply that you can’t install the binary on Catalina, but I don’t think that’s true either. So these instructions are pretty confusing at the moment.
The Mac toolchain has simplified of late. On recent releases, you should be fine with clang from command line tools or from Xcode, as documented on https://mac.r-project.org.
You should be aware of a compiler issue that affects Xcode 12.2 and potentially Xcode from 11.6 onwards (Xcode 11.5 is the last version that I tested prior to upgrading to Mac OS 11.0.1; I am certain you did not need the flag there for RStan and brms): https://stat.ethz.ch/pipermail/r-sig-mac/2020-November/013789.html. FWIW RStan if fine for me on Big Sur. I compiled R from source so I use -Wno-implicit-function-declaration by default. Also, my testing was cursory and not extensive. But so far so good.
@MichiganWater Were you able to get things running successfully in Catalina? Like @Anirban_Mukherjee said I think you should be OK just with Xcode installed (and R >= 4.0). But definitely let us know if you need more help.
Thanks for following up, @jonah. I haven’t attempted to move forward as of yet. I know that getting things wrong during installation can be a huge pain down the line, and since you tagged @bgoodri I’ve been waiting for him to chime in before I proceed. I’m just waiting (patiently!) to find out what the verified correct thing to do is. I’m happy to wait for whenever things are resolved because I know that you all generously donate your time, and I don’t want to presume up on that. Whenever it works with your schedules is good. Fortunately I have a backup (windows) computer I can do things on in the meantime. Thanks again.
That’s true although in this case I think there are some steps you could try that don’t risk messing anything up even if they don’t work:
- Check if you have Xcode installed and if not then install it from the Mac app store
install.packages("Rcpp", repos = "https://rcppcore.github.io/drat")
- Set up Makevars with
dotR <- file.path(Sys.getenv("HOME"), ".R") if (!file.exists(dotR)) dir.create(dotR) M <- file.path(dotR, "Makevars") if (!file.exists(M)) file.create(M) cat("\nCXX14FLAGS += -O3 -mtune=native -arch x86_64 -ftemplate-depth-256", file = M, sep = "\n", append = FALSE)
- Remove any existing installation:
remove.packages("rstan") if (file.exists(".RData")) file.remove(".RData")
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
Even if that doesn’t work then it shouldn’t leave you in too messy of a state.
@bgoodri I just fixed this a second ago but the getting started instructions were also saying that you had to install from source on Catalina, but as far as I know the opposite is true! It’s pre Catalina that now requires installing from source whereas the binary should work with Catalina. Am I right about that? If so then we had the opposite on our instructions page until now when I changed it. Since you are by far the most familiar with all the different RStan installation peculiarities, can you please go through the instructions again and make sure they’re up to date? I fixed a bunch of things but there may be more and even what I fixed may be incorrect since I don’t know all the details.
I finally got this to work after a whole day of trying and re-trying things. Needed to download Xcode, which not sure why this is not mentioned in the instructions ANYWHERE. Thanks to @anirban_mukherjee comment for highlighting this, and then linking to the following (https://mac.r-project.org/tools/) because I needed to also download fortran compiler. Then I followed the instructions at the following link (https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-a-Mac) starting with installing rcpp.
I am on Big Sur and have been having this issue for a long time since I was on Catalina. Better and more clear instructions would be appreciated.
So sorry for the hassle, that’s super annoying! I’m glad it’s working now.
I don’t know why that isn’t mentioned anywhere but it should be if it’s necessary.
Yeah I agree. The current instructions are not sufficient. Some of that is because unfortunately they are constantly evolving, but that’s not the whole story (edit: I mean we could be better organized about it). There’s just a lot of confusing and missing information. I am going to make it a priority to figure out how we can keep the instructions up to date and much clearer and I’m sorry again for the hassle.
Re: the C++ compiler, AFAIK it should be sufficient to install command line tools from Xcode (strict subset of what you get with Xcode). If you have Xcode, you don’t need command line tools. To get command line tools, type “xcode-select --install” in a terminal window. The upside is a much smaller download and footprint in terms of disk space. Re: the Fortran compiler, the GFortran compiler from the R for Mac developer page is the correct compiler. n general, to use R from Mac as a developer and heavy user, these are important parts of the toolchain and things that are good to have. You may also want to know about homebrew (https://brew.sh) that should help you get any other missing libraries or software.
@MichiganWater bgoodri updated the instructions, so I think you can give it a try now. The instructions recommend the R toolchain installer for Mac, which should work for your OS with R > 4.0, but @Anirban_Mukherjee is also right that Xcode (or even a subset of Xcode) will also work.
After a few attempts (warnings, Xcode requested to be downloaded so I did, etc) I think it’s working fine. I’ve tried the
example(stan_model, package = "rstan", run.dontrun = TRUE) code, and there were no issues, so I’ll just start working and check back if I hit any roadblocks. Thanks for the help.
For completeness: the R tool chain installer does 2 things:
- It tidies up a few things like Makevars.
- It downloads CLT from Xcode (includes Clang, a C++ compiler) and GFortran (a Fortran compiler), which are the two official compilers for R on Mac.
If you have already downloaded Xcode or CLT from Xcode and the official Fortran compiler, you don’t need to use the R tool chain installer. If you are starting from scratch then the R toolchain installer is a great way to get setup. One thing to keep in mind, however, is that this is not an official R toolchain installer. It installs the official compilers and the script seems fine but the toolchain installer is developed and maintained by a separate developer. In the long run, the extent to which the installer will remain in sync with CRAN is up to this developer.
I’m not sure if it’s best for me to reply on this thread (since my problem is related to this one) or make a new one so please let me know if it’s better to make a new one!
I’m trying to install Rstan on MacOS Catalina 10.15.7 but I’m having some trouble (I have R version 4.0.3 and Rstudio 1.2.5019). I’ve tried following the instructions and also some of the recommendations on this thread but nothing seems to be working.
I have XCode downloaded and also the GFortran compiler mentioned in a few of the comments above. I have successfully installed RCPP but when I try to install Rstan from source, I get an error which is easily a couple hundred lines long.
Any advice would be really greatly appreciated!