R 4.0, rstan, and you

“Do you want to install from sources the packages which need compilation?”
Yes?

Yes

Instead of the warning message you indicated, I got:
Warning message:
In example(stan_model, run.dontrun = TRUE) : no help found for ‘stan_model’

Thank you for all your help by the way

Oops, I forgot to include the instruction to load RStan first:

library(rstan)
example(stan_model,run.dontrun = TRUE)

This looks like what you were talking about (below), but I am still getting errors in RStudio when trying to run rstan commands or install rethinking.

library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Do not specify ‘-march=native’ in ‘LOCAL_CPPFLAGS’ or a Makevars file
example(stan_model,run.dontrun = TRUE)

stn_md> stancode ← ‘data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}’

stn_md> mod ← stan_model(model_code = stancode, verbose = TRUE)

TRANSLATING MODEL ‘73fc79f8b1915e8208c736914c86d1a1’ FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model ‘73fc79f8b1915e8208c736914c86d1a1’.
COMPILING THE C++ CODE FOR MODEL ‘73fc79f8b1915e8208c736914c86d1a1’ NOW.
OS: x86_64, mingw32; rstan: 2.21.2; Rcpp: 1.0.5; inline: 0.3.15
Error in withr::set_makevars(new, path, state, assignment = assignment) :
Multiple results for CXX14FLAGS found, something is wrong.FALSE
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/rtools40/usr/mingw_/bin/g++’ not found

Something else I missed!

Can you try running:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars.win")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS += -O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2",
     file = M, sep = "\n", append = FALSE)

And then restart R and try the example again?

1 Like

It ran a bunch of code and eventually spat out (below). In a new markdown file, I tried calling the rstan library and am still getting no package called rstan. I have to put this away for now but I really appreciate your help and will check back later.

<U+2714> Packages successfully installed.
There were 50 or more warnings (use warnings() to see the first 50)

OS X:
Install R >4.0.1 , latest RStudio Desktop, latest Xcode development toolkit (check with xcode-select --install in the terminal), install rstan.

For fortran I don’t recall where I got it from, but my Makevars look like this:

CXX14FLAGS=-O3 -mtune=native 
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256 -Wno-unused-local-typedefs -Wno-unused-function
FC = /usr/local/bin/gfortran
FLIBS = -L/usr/local/lib/gcc/10 -L/usr/local/lib -lgfortran -lquadmath -lm

i.e., no -march=native flag.

2 Likes

Thanks! I’ll ping you when I’ve got something drafted

3 Likes

I keep seeing non-zero exit status for pkgbuild and callr.
For rstan it says unpacked and md5 sums checked.
I googled non-zero status and found that that means error and it wasnt installed?

Also then I tried installing rethinking and got this (I have R version 4.0.2)
Installing package into �C:/Users/AACH4770/Documents/R/win-library/3.4�
(as �lib� is unspecified)
Warning in install.packages :
package ‘rethinking’ is not available (for R version 3.4.3)

Once rstan is installed you can install rethinking,

install.packages(c("coda","mvtnorm","devtools","loo","dagitty"))
devtools::install_github("rmcelreath/rethinking")

I don’t think that you’re on R4.0.2. This error:

package ‘rethinking’ is not available (for R version 3.4.3)

Implies that RStudio is using R 3.4.3. If you have have 4.0.2 installed, you can follow this guide to get RStudio to use it: https://support.rstudio.com/hc/en-us/articles/200486138-Changing-R-versions-for-RStudio-desktop

I realize how that sounds but…
image

Just realized I have 4.0.2 but I havent uninstalled prev. versions… Will try.

Just realized I have 4.0.2 but I havent uninstalled prev. versions… Will try.

After that, can you run:

devtools::session_info()

If it throws an error about devtools not being installed, then run:

install.packages("devtools")

and try again

This fixed my issues with rstan on windows 10, thanks a lot. Can you explain what this is?

The error:

Error in withr::set_makevars(new, path, state, assignment = assignment) :
Multiple results for CXX14FLAGS found, something is wrong.FALSE

Is caused by having multiple CXX14FLAGS lines in the Makevars.win file. The command I posted overwrote the Makevars file leaving only one line

1 Like

Hi. Just upgrades to MacOS Big Sur11.2 and R4.0.3. (from Catalina and R3.6.2).
Found my way here and changed the .Renviron and .Makevars filenames as suggested. Stan works - yay… But… I’m getting a cryptic message before it works telling me clang is missing and to start an issue on Github:

library(rstan)
scode <- "
parameters {
  real y[2]; 
} 
model {
  y[1] ~ normal(0, 1);
  y[2] ~ double_exponential(0, 2);
} 
"

I figured before I go starting Github issues I should ask here is this something to ignore or what… after all stan worked after flashing this message.

1 Like

Go ahead and make an issue on the Github. This model looks like it shouldn’t give any errors.

The Stan compiler got rewritten recently. What happens is when you compile a model, rstan is compiling it with the old compiler and the new compiler. It uses the results from the old compiler to run, but if the new compiler causes an error it directs you to report a bug. The goal here is to make sure when we switch to the new compiler there are as few errors as possible (so go ahead and file the report – this definitely seems like a model that should work).

1 Like

This one is a false positive and is flagged due to the clang++ error in the first line.

So this is a toolchain issue but just manifests this way.

Search for that error in the github rstan repository. There are at least a few of them with suggestions how to fix them.

1 Like

Oooh, I see. Makes sense. Alright so maybe there’s toolchain a fix hidden somewhere on the Github.

1 Like