Trouble building an rstan-dependent package on r-universe

The R package blavaan depends on rstan and compiles a Stan model at installation. The package passes the CRAN checks and also works locally. But the r-universe builds are failing with a “stan/version.hpp: No such file or directory” error. I first thought it might be related to the fact that the r-universe Stan packages are at different versions as compared to CRAN. But I believe that r-universe is using the CRAN versions of Stan packages in the blavaan build. Now I am unsure how to proceed.

The r-universe logs of the failed build can be seen here. I appreciate any ideas or hints!

I know @avehtari has recently been looking at r-universe, but @andrjohns might be the best person to answer this. Looking at the logs and the StanHeaders artifact, the version.hpp file is in include/src/stan/version.hpp, but the -I flags only feature the include folder, not also include/src.

2 Likes

We had the same problem - the fix is to remove NeedsCompilation: yes from the DESCRIPTION file. This is added at build time automatically.

More detail at install cmdstanr from multiverse by sbfnk · Pull Request #1130 · epiforecasts/EpiNow2 · GitHub

5 Likes

Thanks for figuring this out! Is this true on CRAN too or just R-universe? It’s interesting that @edm reported that CRAN checks were passing but R-universe checks were failing.

Thanks to @sbfnk! I can confirm that removing the NeedsCompilationline fixed this R-universe problem for me.

Also, I have had NeedsCompilation: yes in my DESCRIPTION for a long time, and it never bothered CRAN (as recently as two weeks ago).

1 Like

Indeed this seems to be specific to R-universe. That said Writing R Extensions states that

The ‘NeedsCompilation’ field […] is normally set by R CMD build or the repository assuming compilation is required if and only if the package has a src directory.

which makes me think that indeed we shouldn’t set NeedsCompilation if we generate src only at build time through rstantools::rstan_config(). R-universe applies a “fix” if the metadata is inconsistent (NeedsCompilation: yes and no src/ directory) which broke our package installs.

2 Likes