Errors getting my old R package that depends on the stan math library to build


In November 2017 I created my own R Package that made use of Stan’s math library (primarily autodiff). I revisited that package today to make some adjustments and RStudio is reporting errors in the build that seem to be associated with the math library. In addition to (what I think are harmless) warnings such as:

  • pragma diagnostic pop could not pop, no matching push
  • ‘auto’ type specifier is a C++11 extension

I get many errors along the lines of:

*expected expression in line 2 of …/stanheaders/include/stan/math/prim/mat.hpp

  • a space is requires between successive right angle brackets (use ‘>>’) in line 56 of …/stan/mat/meta/operandsandpartials.hpp
    *unknown type name ‘constexpr’ in line 5 of …/prim/mat/fun/matrix_exp_multiply.hpp

My package won’t build because of these errors. It used to build in early 2018, and I haven’t changed anything in the mean time. Does anyone have any ideas what might be causing this or how to fix it? I can provide a full list of all of the reported errors and warnings if it would be more helpful, but the above are typical examples. I’ve made sure I have the latest versions of R, rstan, rstudio, and boost installed. My operating system is macOS Sierra Version 10.12.6.



You need to require the CXX14 standard by putting a line like

into src/Makevars and src/ .


Thank you! I should have come here sooner.

Unfortunately, now I am encountering the problem discussed here:

in that stan::math::ChainableStack::memalloc_.free_all(); doesn’t seem to work anymore. If I comment it out my package will compile, but runtime ends up being far slower than it used to be. Does anyone know of a fix for the issue above?


Actually, it seems as though I might have spoken too soon. As long as I don’t also comment out the line


the run time issue seems to disappear. That is, the code


seems to run fine but

// stan::math::recover_memory();

is slow. I don’t know much at all about memory, but as of right now it doesn’t seem to a big issue anymore.