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

Kevin Ushey kevinushey at gmail.com
Thu Apr 4 20:36:35 CEST 2019

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

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.


On Thu, Apr 4, 2019 at 10:32 AM Fernando H Toledo
<fernandohtoledo at gmail.com> wrote:
> Dear All,
> Recently Tomas Kalibera has post on the blog of R developers about the
> use o C++ in R packages.
> The post can be seem at the following link:
> https://developer.r-project.org/Blog/public/2019/03/28/use-of-c---in-packages/
> I would like to know your thoughts over that. In summary, he recommend
> to avoid C++ in R packages but for me his points are not too clear.
> Maybe you can help me to clarify them.
> Cheers,
> FH
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

More information about the Rcpp-devel mailing list