`rstan` missing `BH` from imports / suggests
Summary:
It appears that rstan requires the BH to be available at run time when it compiles the Stan models otherwise an error is thrown e.g.
> stan_model <- stan_model(model_code = model)
Error in stan_model(model_code = model) :
Boost not found; call install.packages('BH')
However Stan doesn't list BH in it's imports or suggests but instead only in it's LinkingTo field.
From CRAN Writing R Extensions:
Note that ‘LinkingTo’ applies only to installation
This doesn't usually cause an issue as install.packages() includes LinkingTo packages by default however the pak installer takes a more strict view and won't install LinkingTo packages if it is installing binary packages (The logic being they are already compiled so the LinkingTo headers are redundant).
This is currently an issue when trying to use the Rhub pipelines for testing packages as they are dependent on pak for installing dependencies
https://github.com/insightsengineering/rbmi/actions/runs/11362703172/job/31605118630#step:5:1762
I originally raised this with the Rhub developers who suggested that I raise an issue here in order to get the Stan DESCRIPTION file updated to resolve this
https://github.com/r-hub/rhub/issues/642
Reproducible Steps:
- Install Rstan
- Remove BH if it was automatically installed
- Run any Stan model and it will throw an error that BH is missing
Current Output:
NA
Expected Output:
NA
RStan Version:
2.35.0.9000
R Version:
R version 4.4.1 (2024-06-14)
Operating System:
MacOS 14.6.1
Thanks for reporting. Hopefully this will be an easy fix.
Thanks. I think a long time ago there may have been some issue with including BH in Imports and for that reason custom code was added to check for BH and tell the user to install it if not found. I don't remember exactly why that was necessary and I could be wrong. I think @bgoodri would know. @bgoodri do you remember that? Or should we just go ahead and add BH to Imports?
I believe I am also encountering this issue when checking R packages via rhub. Would there happen to be any updates or workarounds? Thank you all!
@bgoodri? Should we just add BH to imports? It seems like we should if that's the strictly correct thing to do accoding to R.
I'm not entirely sure what the historical issue was here but I am wondering if it is due to R CMD check. That is, BH doesn't define any R objects, I mean it literally doesn't have an R/ folder in the code base so there are no direct R objects to make use of. Thus if you add it to the import list you always get the following R CMD check note:
N checking dependencies in R code (2.4s)
Namespaces in Imports field not imported from:
‘BH’
I think this is fine though, I think you just have to explain the note in your cran-comments.md file when uploading to CRAN e.g. https://github.com/swarnendu-stat/bnns/blob/master/cran-comments.md https://github.com/InsightRX/PKPDsim/blob/master/cran-comments.md
~~Having said that I'm not quite sure I fully understand how this check works. For example the following repo also imports BH yet someone doesn't raise any such NOTE in their R CMD check log:~~
~~https://cran.r-project.org/web/checks/check_results_GBJ.html~~
~~https://github.com/search?q=repo%3Aryanrsun%2FGBJ%20BH&type=code~~
Edit - They got around that by having an import() directive in their NAMESPACE file but not actually including BH in the imports: field of their DESCRIPTION file. I don't think that would help here as I don't think that guarantees that BH is actually installed.
I stumbled upon this issue, while looking into a related problem when using r-cran-rstan v2.21.7-1 + r-cran-bh v1.74.0-2 from Debian/bookworm. It's working fine for me with Debian/trixie and its r-cran-rstan v2.32.7-1 + r-cran-bh v1.84.0-1 though, see https://bugs.debian.org/1108078 (just if it helps anyone else).