Skip to content
Prev 10309 / 10988 Next

[Rcpp-devel] R/C++ post on R Devel Blog

I think Tomas's post is clear and quite helpful, I just disagree with
the conclusions. IMHO C++ (through Rcpp) is still the best way to
interface with R from compiled code for the majority of users.

Tomas's comments were mainly around the fact that things can go wrong
if you start mixing R longjmp's with C++ destructors. This is why Rcpp
encourages things like:

   - Use Rcpp::stop() in preference to Rf_error();
   - Use Rcpp::eval() in preference to Rf_eval();

And so on. I think it's unfortunate that Tomas's conclusion is to use
C rather than C++, as writing correct C programs is, in my opinion and
experience, substantially more difficult than writing correct C++
programs -- especially when using modern C++ programming idioms.

I also strongly believe that users have better things to do than
manually manage protection of R objects, especially since Rcpp can
manage that for you. Things are still not perfect, as Tomas pointed to
a very real bug with the use of RNGScope, but it's still IMHO a
substantial improvement over what needs to happen in equivalent C
code.

Ultimately, I think the lesson is: don't call R's C API directly from
C++ code unless you absolutely know what you're doing.

Best,
Kevin


On Thu, Apr 4, 2019 at 10:32 AM Fernando H Toledo
<fernandohtoledo at gmail.com> wrote: