<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">
<br>
</div>The same trick was already used in RcppDE (which was a proof of concept about<br>
converting DEoption from 700 lines of plain C to 400 lines of C++ / Rcpp)<br>
where I have<br>
<br>
typedef double (*funcPtr)(SEXP);<br>
<br>
and the rest works like a 'plain old package'.<br></blockquote><div><br></div><div>Certainly. And while I haven't implemented the switching between C++ and R functions, when I use `sourceCpp` to compile and load the file, everything seems to work.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
| My (perhaps naive) attempts are giving errors about my `funcPtr` type not being<br>
| defined. I've tried moving this definition to a header file, but even with `//<br>
| [[Rcpp::depends(myheader)]]` or `\\[Rcpp::depends(myheader.h)]]`, the generated<br>
| RcppExports.cpp file does not include `myheader.h`.<br>
<br>
</div>What exactly is the error?</blockquote><div><br><br>Error:<br><br>make[1]: Entering directory `/tmp/RtmpTfIlij/R.INSTALL4a2441f79c5/RItools/src'<br>g++
-I/usr/include/R/ -DNDEBUG -D_FORTIFY_SOURCE=2
-I"/home/mark/Documents/Software/RItools/.local/Rcpp/include" -fpic
-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector
--param=ssp-buffer-size=4 -c RcppExports.cpp -o RcppExports.o<br>RcppExports.cpp:59:6: error: ‘testStat’ was not declared in this scope<br> XPtr<testStat> testStatisticPtr(std::string f);<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Could it be as simple as missing<br>
<br>
-I.<br>
<br>
in src/Makevars ? That is not added by default so try adding the line<br>
<br>
PKG_CPPFLAGS = -I.<br>
<br>
(not indented, of course) to src/Makevars (and src/Makevars.win)<br></blockquote><div><br></div><div>Thanks for the suggestion, though it does not resolve the above issue. The generated RcppExports.cpp:<br><br>// This file was generated by Rcpp::compileAttributes<br>
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393<br><br>#include <Rcpp.h><br><br>...<br><br></div><div>// testStatisticPtr<br>XPtr<testStat> testStatisticPtr(std::string f);<br>RcppExport SEXP RItools_testStatisticPtr(SEXP fSEXP) {<br>
BEGIN_RCPP<br> SEXP __sexp_result;<br> {<br> Rcpp::RNGScope __rngScope;<br> Rcpp::traits::input_parameter< std::string >::type f(fSEXP );<br> XPtr<testStat> __result = testStatisticPtr(f);<br>
PROTECT(__sexp_result = Rcpp::wrap(__result));<br> }<br> UNPROTECT(1);<br> return __sexp_result;<br>END_RCPP<br>}<br><br></div><div>---<br><br></div><div>The issue being that my local teststatistics.h is not included, so the typedef is not visible when compiling this file.<br>
</div><div><br></div><div>I suspect the solution is just to write the export wrapper for this particular function manually (I could just copy and paste). That way RcppExports.cpp never has to deal with the typedef.<br><br>
</div><div>Thanks for help,<br></div><div>-Mark<br><br></div></div></div></div>