[Rcpp-devel] design, class names, namespaces, etc ...

Romain François francoisromain at free.fr
Tue Dec 29 17:24:05 CET 2009


On 12/29/2009 03:39 PM, Dirk Eddelbuettel wrote:
>
> (bending this one back onto the list...)
>
> On 29 December 2009 at 14:21, Romain François wrote:
> |>  | Yes, there is the explicit asSexp but you have to call it. operator SEXP
> |>  | makes it possible to return the RcppSexp and the compiler figures out
> |>  | that it should return the SEXP instead.
> |>  |
> |>  | So instead of this :
> |>  |
> |>  | cat("===Doubles\n")
> |>  | foo<- '
> |>  |          double d = RcppSexp(x).asDouble();
> |>  | 	std::cout<<   "Returning twice the value of"<<   d<<   " : ";
> |>  | 	return(RcppSexp( 2*d ).asSexp());
> |>  |          '
> |>  | funx<- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
> |>  | cat(funx(x=2.123), "\n")
> |>  |
> |>  | We can now do:
> |>  |
> |>  | cat("===Doubles\n")
> |>  | foo<- '
> |>  |          double d = RcppSexp(x).asDouble();
> |>  | 	std::cout<<   "Returning twice the value of"<<   d<<   " : ";
> |>  | 	return(RcppSexp( 2*d ));
> |>  |          '
> |>  | funx<- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
> |>  | cat(funx(x=2.123), "\n")
> |>  |
> |>  | the difference being on the return line.
> |>
> |>  Damn that is nice. And darn close to magic!
> |
> | Item 5 of More Effective C++ does not say nice things about it. I'll
> | read it again.
>
> I don't have a copy available right now. What does it say?

Essentially it says that it is not only magic when you want it but also 
when you might not expect it. Example :

RcppSexp x( 2 ) ;
RcppSexp y( 2 ) ;
x == y

does not work right, because we don't have an operator== defined for 
RcppSexp. well, in fact it compiles and behind the scenes the compiler 
compares the underlying SEXP of x and the underlying SEXP of y, these 
are pointers, so they are compared as pointers, so not only it compiles, 
but it also give a wrong result.

for this reason i have not added implicit conversions for other types : 
bool, double, ...  but knowing this i will implement == correctly.

> |>  I was thinking that we may even have enough new stuff to call it 0.8.0
> |>  instead of 0.7.1.
> |
> | sure, please hold the releasing. Right now, I am factoring some things
> | out of RcppSexp into a new class RcppSuperClass which deals with all
> | things that can be related to any SEXP (attributes, is it NULL,
> | protection from GC, ...
> |
> | The naming is a bit awkward, maybe RcppSuperClass should be called
>
> The name is awful :)

Changed my mind anyway, now RcppSexp is the main class and RcppXPtr<> 
extends it.

> | RcppSexp and RcppSexp something else since it really only deals with
> | integer, numeric, character, and raw vectors. Can't call it RcppVector
> | because it already exists. What do you think.
>
> RcppSimple ?
> RcppTransfer ?
> RcppUtil ?
>
> add a namespace and call it rcpp::Sexp ?  [ I'd rather add a namespace for
> all of them at once. And maybe add typedefs to ease transition. To be seen. ]

I'll go with the namespace stuff as I don't like the namespace wanabee 
of prefix all the class names with Rcpp. I need to check if some other 
package does not already use the "rcpp" namespace, in case Rcpp and the 
other package are used at the same time.

What about something like "Object" as the main class, or "RObject". I 
think CXXR uses one of these.

or "REXP" as in Simon's java code.

> |>  Also, shall we move some of the inline'd tests from inst/examples/RcppInline
> |>  to tests/ -- possibly with similar RUnit magic as in RProtoBuf ?  We really
> |>  do use this as unit tests (and that is a good thing).
> |
> | Now you start reading my mind.
>
> Yup. But we can do without the unittest vignette. Not sold on that one.

I understand. It is not currently what I have in mind, but when it is 
I'll try to sell it again.

What I really like about it is that it runs at 'R CMD build' time, so 
the source tarball already contains evidence that it is tested.

> Dirk
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/IlMh : CPP package: exposing C++ objects
|- http://tr.im/HlX9 : new package : bibtex
`- http://tr.im/Gq7i : ohloh





More information about the Rcpp-devel mailing list