Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Stan code vignette compilation error on docs pages #82

Open
santikka opened this issue May 21, 2024 · 6 comments
Open

Custom Stan code vignette compilation error on docs pages #82

santikka opened this issue May 21, 2024 · 6 comments

Comments

@santikka
Copy link
Collaborator

@mpadge We're getting a compilation error on the rOpenSci docs pages for one vignette (see the third code block): https://docs.ropensci.org/dynamite/articles/dynamite_custom.html, could you provide any insight into what might be happening? Curiously though the fit object still seems to be accessible in the next code block unless it is using a cached result somehow. The example runs without issues locally.

@mpadge
Copy link
Member

mpadge commented May 22, 2024

I have no idea. cmath should be part of std in any installation. It's pulled in whenever any routine anywhere in the compilation chain requires any function defined there, so should never be missing in practice. You can't directly pull it in here because you've got no source code. There error can't directly arise from RcppEigen either, because the #include <cmath> statements there are perfectly legitimate. I can only guess as you suggest that there's some kind of cache issue happening. @jeroen Any ideas?

@jeroen
Copy link
Member

jeroen commented May 22, 2024

This error happens because it is trying to compile c++ files with gcc (the c compiler) instead of g++.

@helske
Copy link
Collaborator

helske commented May 29, 2024

But why is it doing so? This seems to happen now with other models as well, e.g. https://docs.ropensci.org/dynamite/articles/dynamite.html#sec:seatbelt. Same code runs without error locally and in github actions, as well as in r-universe: https://ropensci.r-universe.dev/articles/dynamite/dynamite.html which I though was used in the pkgdown site as well?

I can't find exactly the same issue with google, but I've encountered similar issues sometimes when somekind of mismatch with the versions of various packages used by rstan (e.g., BH, RcppEigen, StanHeaders, RcppParallel) and/or compilers.

@mpadge
Copy link
Member

mpadge commented May 29, 2024

Dunno. The include flags (-I) are pulling in the C++ headers from Rcpp, RcppEigen, and BH for a "simple C file":

> Trying to compile a simple C file
#> Running /usr/lib/R/bin/R CMD SHLIB foo.c
#> using C compiler: ‘gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0’
#> gcc -I"/usr/share/R/include" -DNDEBUG   -I"/usr/local/lib/R/site-library/Rcpp/include/"  -I"/usr/local/lib/R/site-library/RcppEigen/include/"  -I"/usr/local/lib/R/site-library/RcppEigen/include/unsupported"  -I"/usr/local/lib/R/site-library/BH/include" -I"/usr/local/lib/R/site-library/StanHeaders/include/src/"  -I"/usr/local/lib/R/site-library/StanHeaders/include/"  -I"/usr/local/lib/R/site-library/RcppParallel/include/"  -I"/usr/local/lib/R/site-library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1       -fpic  -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/r-base-RCJDS4/r-base-4.4.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/r-base-RCJDS4/r-base-4.4.0=/usr/src/r-base-4.4.0-2.2404.0 -Wdate-time -D_FORTIFY_SOURCE=3  -c foo.c -o foo.o

Something going wrong in cmdstanr? I'd check there.


Update: You could step through rstan/R/stan.R, which should return a strict C object long before it pulls in the C++ headers. Seems like something there is failing.

@helske
Copy link
Collaborator

helske commented May 30, 2024

The example is using rstan, not cmdstanr, but it's difficult to debug this as we see this issue only on the ropensci pkgdown site.

@santikka
Copy link
Collaborator Author

As a workaround in 6a01d3e, I've wrapped all model fits in the vignettes with invisible(capture.output(...)) with error = FALSE, message = FALSE, warning = FALSE in the chunk options. This at least prevents the Trying to compile a simple C file "errors" from being displayed, as they don't seem to influence the actual model fitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants