[Rcpp-devel] Idiom for accessing scalars

Douglas Bates bates at stat.wisc.edu
Fri Jan 6 20:46:01 CET 2012


On Fri, Jan 6, 2012 at 1:12 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 6 January 2012 at 12:59, Douglas Bates wrote:
> | On Fri, Jan 6, 2012 at 12:39 PM, John Chambers <jmc at stat.stanford.edu> wrote:
> | > The "Rf_" part of the API in particular is ugly and somewhat of an add-on
> | > forced in a few examples by the use of some common names in the macro files.
> |
> | But, as it stands, that is a requirement when using Rcpp.
>
> Where?  I can think of one propagated use, which is at the bottom of the
> try/catch structure where we use ::Rf_error.  But the commonly used macros
> hide it, and we could/should obviously wrap this.
>
> Otherwise, and especially since the 'Rcpp sugar' initiative took off, I don't
> really touch any ::Rf_* myself anymore.  Inside the Rcpp code base, sure. But
> not really in user-facing stuff and Rcpp applications.

I didn't make myself clear.  What I meant was that it is not possible
to use asInteger in Rcpp and count on the name being remapped to
Rf_asInteger.

> | I think of the Rf_ part as more due to the fact that C doesn't have a
> | concept of namespaces so anything in the R API is at the top level
> | namespace leading to some conflicts.
>
> Agreed.  But speaking stylistically, for the same reason that we prefer C++
> versions of C header files (eg cstdint over stdint.h, cstdio over stdio.h,
> ...) I am with John on the preference for C++ idioms when given a choice.

I suppose I could have just checked whether Rcpp::as<int> calls
Rf_asInteger.  If so, everything is cool.  Unfortunately, I haven't
been able to find that specialization.


More information about the Rcpp-devel mailing list