[Rcpp-devel] #ifdef'd out // [[Rcpp::export]]

Greg Minshall minshall at umich.edu
Mon Feb 25 00:07:13 CET 2013


J J,

thanks.  actually, if you track the source file line number, and inject
"#line" directives around your injections, you don't need to rewrite
error messages.

e.g., let's say we're at line number 77 of file cluster.cc, and we see:
----
// [[Rcpp::export]]
int int_lots_in_one_out(std::list<int> il) {
    return il.front();
}
----

we could output (if this were the first injected chunk):
----
// [[Rcpp::export]]
#line 1 "Rcpp::attributes::injected"
#include <Rcpp.h>

RcppExport SEXP sourceCpp_7387_int_lots_in_one_out(SEXP ilSEXP) {
BEGIN_RCPP
    Rcpp::RNGScope __rngScope;
    std::list<int> il = Rcpp::as<std::list<int> >(ilSEXP);
    int __result = int_lots_in_one_out(il);
    return Rcpp::wrap(__result);
END_RCPP
}
#line 78 "cluster.cc"
int int_lots_in_one_out(std::list<int> il) {
    return il.front();
}
----

(where "Rcpp::attributes::injected" is whatever string makes sense.)

(in the currenct model, one #line directive might be good to do *before*
you inject code, since right now the line number on error messages in
the injected code (say, because of a user -- i.e., me! -- error) are
larger than the number of lines in the file, and confused, at least, me.
with the #line directive, hopefully the user will recognize where to
look (in the tempdir() file, or in "verbose=TRUE" output, say).

cheers, and much appreciation, Greg

ps -- there's at least *some* possibility the preprocessor eats the line
directive.  at least on my local systems (mac, linux) this isn't the
case.


More information about the Rcpp-devel mailing list