stan-dev / rstantools

Tools for Developing R Packages Interfacing with Stan
https://mc-stan.org/rstantools
GNU General Public License v3.0
51 stars 21 forks source link

Conflict with RcppArmadillo and Rcpp when exporting `.stanfunctions` #127

Open helske opened 3 months ago

helske commented 3 months ago

Sorry that I don't have a minimal example at the moment, but I can create one if needed.

I'm trying to export some Stan functions to R in a package which also includes C++ code using RcppArmadillo. I have a file Rexports.stanfunctions in inst/stan, but when installing the package I get an error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'.". This seems to be due to the incorrect order of including RcppArmadillo and Rcpp headers because in the autogenerated RcppExports.cpp file<packagename>_types.h is included first (such file is not created when there are no Stan functions to be exported):

#include "packagename_types.h"
#include <RcppArmadillo.h>
#include <RcppEigen.h>
#include <Rcpp.h>

The first include contains exporter.h from Rcpp which seems to mess things. Moving the first line to last after other includes seems to get rid of the error.