How to generate an R warning safely in Rcpp
问题 We know that calling Rf_error() should be avoided in Rcpp as it involves a longjmp over C++ destructors on the stack. This is why we rather throw C++ exceptions in Rcpp code (like throw Rcpp::exception("...") or via the stop("...") function). However, R warnings may also result in a call to Rf_error() (this behavior depends on the warn option). So, a call to Rf_warning() is also risky. Rcpp::sourceCpp(code = ' #include <Rcpp.h> using namespace Rcpp; class Test { public: Test() { Rcout <<