You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Warn (or initially message) if R headers included before Rcpp headers #1410
Over the years, programming practice has evolved and improved when it comes to header inclusion and spillover of defintions. For example, as of release 4.5.0 R now makes R_NO_REMAP a default for inclusion from C++ code (WRE, Chapter 6), and Rcpp has long done so too via the file inst/include/Rcpp/r/headers.h. The #define STRICT_R_HEADERS is another example.
To be most effective, the header includes should happen in a controlled order. As Rcpp itself includes the R headers after making certain definition itself it is preferable to not include R headers before Rcpp does. So far, we have not checked for this, and it may be time to change this.
Conceptually, things start for us from RcppCommon.h which first includes Rcpp/r/headers.h. We could precede this with header file checking for symbols i.e. something along the lines of
#if defined(R_R_H) & defined(USING_R)
#pragma message "R.h has been included before any Rcpp headers. This can lead to hard-to-debug errors, \
and is generally not necessary. See https://github.com/RcppCore/Rcpp/issues/1410"
#endif
We could leave this at 'message' level for some time (a year?) and then switch to 'warning'. For comparison, RcppArmadillo relies on a fairly intricate interplay between Rcpp headers and its own and made it an error of Rcpp was included first. This has been in place for years, and works well. We probably also want to check for Rinterface.h, Rdefines.h and Rinternals.h, and possibly more. I have a local test branch I can push is other want to play along.
PS We could and should also over an override to skip the check in case someone bulk compiles or installs and doesn't want to see it, i.e. wrap it all in #if !defined(RCPP_SKIP_CHECK_FOR_R_H) or alike.
We could leave this at 'message' level for some time (a year?) and then switch to 'warning'. For comparison, RcppArmadillo relies on a fairly intricate interplay between Rcpp headers and its own and made it an error of Rcpp was included first. This has been in place for years, and works well. We probably also want to check for Rinterface.h, Rdefines.h and Rinternals.h, and possibly more. I have a local test branch I can push is other want to play along.
Activity
Enchufa2 commentedon Nov 24, 2025
+1
Enchufa2 commentedon Nov 24, 2025
Maybe
RCPP_NO_R_HEADERS_CHECKorRCPP_NO_USING_R_CHECK? Because we have severalRCPP_NO_*already, but noRCPP_SKIP_*ones.eddelbuettel commentedon Nov 25, 2025
Closing now as #1411 is merged.