Rstan installation troubles

Yeah, I don’t think its specific to RStudio. I don’t even think its specific to Windows 11. As I mentioned, my laptop runs Windows 11, and installing RTools and rstan for source worked perfectly fine without any complications whatsoever.

Something has gone wrong specifically on this PC. Whatever has gone wrong is not being corrected with simple install/reinstall.

If I knew it would definitely fix the problem, I’m open the idea of completely uninstalling windows and starting again. But, I don’t want to risk going through all that hassle for it to still fail for some other reason.

Do you know of any documentation that describes how to remove ALL traces of R, RStudio and RTools from your computer? IE no lingering files left behind hidden in documents that simply uninstalling sometimes misses.

Sorry, I am usually working under linux and try to avoid Windows as much as possible. :)
But, AFAIK, on pretty much any operating system it is a problem to delete all traces of a program. One can typically erase everything on the system side, but if that program created anything in user space (e.g. private libraries into which R packages are installed if one is not allowed to change the system library) is usually missed. Uninstall programs would have no idea which users all used the software and/or where they installed these user space files.

No problem. Yeah, that is what I figured too. I just can’t think what else I can actually try aside from a full OS reinstallation, which seems a dramatic solution for a relatively simple issue. A solution which isn’t even guaranteed to work…

Thanks for providing the advice you have anyhow. I don’t want to take any more of your time, but if you had any other ideas or knew of any good documentation for thoroughly checking Rtools configuration I’d be keen to hear.

Thank you for your help on this issue @Berwin_Turlach, I was having the same problem. Running those commands from R directly (not from RStudio) allowed me to install from source and solved the problem.

1 Like

I have FINALLY managed to fix the problem and get rstan working and, install packages from source. For the benefit of anyone who finds this thread and faces the same issues, here is what fixed the problem for me. Note, I am using Windows 11 and R version 4.3.0. I suspect this is specific to Windows and Rtools43.

While I am still guessing, it looks like my issue arose because there were lingering conflicting rtools configurations within my path that were stopping the correct version being used. Here is how I fixed it.

First, uninstall all versions of Rtools that you have installed.

Next, search for “system variables” in the search bar and click “Edit the system environment variables”. From there, go to “advanced” and click “Environment variables”.

You will see a whole load of user variables and system variables listed. Go through the list and delete ANY mention of Rtools in any of these places. Specifically, look in “Path”. Do take a lot of care here though, as I bet deleting the wrong thing here could cause all sorts of havoc. If you aren’t sure, double check before deleting anything. Also, make sure to only delete the individual lines that refer to Rtools - don’t delete the entire path/section.

Once you are certain all mentions of RTools has been deleted, click “OK” and close this window. Then, reinstall RTools43 and ensure you install it to the default location (C:\rtools43). Accept all defaults during the installation.

Go back to the Envirionment variables and check that you have a new “System variables” entry that is called: RTOOLS43_HOME and it should have a value of C:\rools43. If you have, great! Everything should now be working.

I hope this can help somebody in the future.


Thanks very much @Ruben222. I am on Windows 11, new R install and having stan problems. I did not need to do the full process you outline. But I think my Rtools43.install did not update PATH and did not set RTOOLS43_HOME. (Possibly because I was not installing as admin). I logged in as an admin, updated PATH and created RTOOLS43_HOME. And when I relaunched RStudio, my stan calls are finally running OK. So thanks again :)

1 Like

Dear @Berwin_Turlach,

Thanks so much for adding that code. I tried running this then running


But I’m coming up with an error message:

Error: package or namespace load failed for ‘rstan’:
.onLoad failed in loadNamespace() for 'rstan', details:
call: NULL
error: SyntaxError: Illegal break statement

then after running:

install.packages(c("rstan", "tidyverse", "devtools"))

I got this error after trying to run library(rstan)

Error: package or namespace load failed for ‘rstan’ in get(Info[i, 1], envir = env):
lazy-load database '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/R/rstan.rdb' is corrupt

Do you have any suggestions on how I could fix this?

Hi Oscar,
Coincidentally, yes, I have an idea. :-)

Disclaimer: from your last error message I infer that you are working on a Mac OS X system, and I have very little experience with that OS.

The first error message I experienced myself the other day. To cut a long story short, StanHeaders 2.26.28 hit CRAN, and that version is incompatible with rstan 2.26.22 from the Stan repository, but rstan 2.26.23 is now on CRAN. Once one installs Stanheaders 2.26.28 and rstan 2.26.23 from CRAN one should have a working set-up.

I presume you are in the same situation as I was, where you are using a CRAN (mirror) that has already the newer version of StanHeaders but not the newer version of rstan on it.

Full details of my experience are at Beware of StanHeaders (2.26.28) from CRAN if you run rstan 2.26.22 from the Stan repository.

The information in this topic is really out-dated and should not be relied on anymore.


It seems like you’re encountering an issue with your RStan installation on Windows 11. The error message suggests a problem with the ‘Makevars’ file. To resolve this, follow these steps:

  • creat the " makevars" file
    Since it’s missing, you can create it manually. Open a text editor and create a new file named ‘Makevars’ (no file extension) in your R home directory. This directory is usually located at C:/Users/user/Documents/R/ .
  • Edit the ‘Makevars’ file : Add the necessary configurations to the ‘Makevars’ file. It should look something like this:
    CXX14 = g++ -std=c++1y
    CXX14FLAGS = -O3
    Make sure to adjust the settings based on your system’s requirements.
    Save the ‘Makevars’ file: Save the file and make sure it’s located in the correct directory.
    Restart R: Close and reopen R to ensure that the changes take effect.

I had the installation issue that resolved after removing “.Renviron”.

Installing package into ‘C:/Users/user/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
also installing the dependency ‘StanHeaders’

Warning in install.packages :
unable to access index for repository
cannot open URL ‘’

There are binary versions available but the source versions are later:
binary source needs_compilation
StanHeaders 2.21.0-7 2.26.22 TRUE
rstan 2.21.8 2.26.22 TRUE

installing the source packages ‘StanHeaders’, ‘rstan’

trying URL ‘ 3’
Content type ‘application/gzip’ length 2758280 bytes (2.6 MB)

Remove the rstan package
Delete the .Renviron file from directory folder
Uninstall Rtools and install it again

Hope be helpful