R Package Maintainers Using Stan - Please Read

You should do whatever works best in your case.

For me it was about building a template package from where I took over the bits into my package. In fact, I followed the vignette from rstantools and even automated building that test package. Attached is the R file for that. In the process of doing that I figured out what was important (the NAMESPACE file must contain a certain minimum).

So maybe just get started and let us know where you get stopped and how. In case all is smooth, then that’s welcome news as well.

Thanks for porting things over as asked for!

rstantools.R (1.6 KB)



I have done the edits GitHub - stemangiola/ppcseq at adapt-to-new-stan

If anyone could confirm that this is correct would be amazing.

1 Like

I don’t see this line in the R/*-package.R:

#' @importFrom RcppParallel RcppParallelLibs CxxFlags

other things look good to me from skimming over it.

Thanks for switching!


Thanks, I will apply to my other packages.

Do you think you will ever be able to make 100% of packages switch? I guess this is the requirement for updating CRAN on your side.

(and thanks for taking the time and energy to push this)

1 Like

No, I don’t think that we will manage to get them all switched… but being able to show that we made an effort should help us making the case with CRAN that we push updates through regardless. In that case downstream packages would vanish from CRAN.

(but maybe, hopefully we find a workaround… a lot of pain for the devs, but we need to get out of the situation we are in right now)

I was left a bit unclear about what should be done if a package has been created with some version of rstantools back in the day. Afterwards I have manually added RcppParallel to Imports and LinkingTo. And why do we need

importFrom(rstan, sampling)

for? I don’t have them and have not had any problems generating documentation using roxygen2. The package is here if you want to check it.

I am not sure how to ensure this:

and also don’t know what this

is for and whether everyone needs it or was it just for stemangiola.

This forum probably doesn’t reach all maintainers. CRAN policy site says

  • If an update will change the package’s API and hence affect packages depending on it, it is expected that you will contact the maintainers of affected packages and suggest changes, and give them time (at least 2 weeks, ideally more) to prepare updates before submitting your updated package. Do mention in the submission email which packages are affected and that their maintainers have been informed. In order to derive the reverse dependencies of a package including the addresses of maintainers who have to be notified upon changes, the function reverse_dependencies_with_maintainers is available from the developer website.

so should you also send an email to all maintainers to get more people to do the porting?

1 Like

I think you need these… for sure the Rcpp thing.

Every package needs that.

I think @bgoodri has written lots of emails as of now. This forum really should reach everyone posting R packages based on Stan…but I agree that this is probably not the case.

We also advertised this post on the Twitter account a few times.

1 Like

I’m restructuring this issue to track the roadblocks for rstan 2.26. I’ve gone through the reverse dependencies and imports from the CRAN page and tested their building against the new RStan and StanHeaders, with the updated rstantools from this PR.

The failures against the 2.21 and 2.26 combo, and the additional failures for the 2.26 and 2.26 combo are below (the full list of tested packages is in this spreadsheet)

RStan 2.21 & StanHeaders 2.26

Package PR Opened
densEstBayes No public repo - Maintainer contacted
dfpk 17-Sep
MADPop 24-Sep
MetaStan 24-Sep
ProbReco 24-Sep
publipha 24-Sep
RxODE 24-Sep
ssMousetrack 24-Sep
stanette No public repo - Maintainer contacted
trialr 24-Sep
visit 24-Sep
RxODE 29-Sep

RStan 2.26 & StanHeaders 2.26

Package PR Opened
beanz 17-Sep
cbq 27-Sep
idem 24-Sep
rstanarm 24-Sep
nlmixr 29-Sep
multinma Needs updated Stanc3 release due to bug
rmdcev Needs updated handling of standalone functions in rstantools
lgpr Needs updated handling of standalone functions in rstantools

Wow, this is fantastic Andrew! Hats off!


This is great, @andrjohns! Could you link the GitHub repo/PR to the package name in your list?

1 Like

A new version of rstan and StanHeaders v2.26.4 is now available to install via:

remove.packages(c("StanHeaders", "rstan"))
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

This version of StanHeaders is compatible with the CRAN version of rstan. It also builds static TBB and shouldn’t need RcppParallel dependency. So, please test it and report any issues.


@andrjohns @bgoodri @wds15 I’ve updated the revdep results for StanHeaders v2.26.4. Now, only 2 packages fail to install (25 failed with v2.26.3) and 4 packages failed in tests. Some of the remaining issues are segfaults or current errors on CRAN.


Great! I’ve already opened a PR over in the ProbReco github and emailed the stanette maintainer with what needs to be changed, so there’s not much more we can do for those

1 Like

Yup, that’s great! And with your effort to inform the maintainers, CRAN shouldn’t complain about 6 (out ~90) packages if we’ve already suggested the required changes weeks before the release.

But, we need to test the current version because static TBB is a major change. As we discussed in the last call, it’s good to use the compatible TBB headers and code from Math, but static TBB might cause hidden issues.


I was wondering how it was going with CRAN. Do we have any time estimate for the update?


1 Like

Dear all, I’ve been developing a package that uses rstan, and saw this thread. After updating StanHeaders and rstan and running rstantools::use_rstan(), my package no longer compiles. Even following the vignette to create a test package ends in a compilation error (below). Is there something obvious I missed? Thank you kindly.

   ERROR: compilation failed for package 'rstanTemplate'
-  removing 'C:/Users/lissa102/AppData/Local/Temp/RtmpK69JjF/devtools_install_557c6bc0e69/rstanTemplate'
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> C:/Program Files/R/R-4.1.2/library/RcppEigen/include/Eigen/src/Core/ProductEvaluators.h:251:23:   required from 'static void Eigen::internal::generic_product_impl<Lhs, Rhs, Eigen::DenseShape, Eigen::DenseShape, 6>::evalTo(Dst&, const Lhs&, const Rhs&) [with Dst = Eigen::Matrix<double, 1, 1, 0, 1, 1>; Lhs = Eigen::Product<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, const Eigen::Matrix<double, 1, -1> >, const Eigen::Transpose<Eigen::Matrix<double, -1, 1> > >, Eigen::Matrix<double, -1, -1>, 0>; Rhs = Eigen::Matrix<double, -1, 1>]'
E> C:/Program Files/R/R-4.1.2/library/RcppEigen/include/Eigen/src/Core/ProductEvaluators.h:124:75:   required from 'Eigen::internal::product_evaluator<Eigen::Product<Lhs, Rhs, Option>, ProductTag, L
Type .Last.error.trace to see where the error occurred

Hmm… all new installation of R, Rstudio and Rtools fixed it.

1 Like

Glad it’s solved now. Thanks for bringing your package up to date.

1 Like