[Rcpp-devel] anyone familiar with the do_dotcode

Romain Francois romain at r-enthusiasts.com
Wed Mar 24 15:22:02 CET 2010


Hello,

I'd like to be able to simply define functions like this :

SEXP foo( IntegerVector x ){
	// .. do something with x
}

instead of this:

SEXP foo( SEXP x){
	IntegerVector xx(x) ;
}

and there is something in do_dotcode (I don't know what) that prevents 
this. With this file :

=====================
#include <Rcpp.h>

using namespace Rcpp;

extern "C" {
	SEXP foo ( IntegerVector x) ;
}

SEXP foo( IntegerVector x ) {
	Rprintf( "hello <%p> \n", x.asSexp() ) ;
	return x ;
}
=====================

compiled into a so with :

romain at naxos /tmp $ export PKG_LIBS=`Rscript -e "Rcpp:::LdFlags()"`
romain at naxos /tmp $ export PKG_CXXFLAGS=`Rscript -e "Rcpp:::CxxFlags()"`

and then :


require( Rcpp)
dyn.load( "foo.so" )
.Call( "foo", 1:10 )


This prints :

romain at naxos /tmp $ Rscript test.R
Le chargement a nécessité le package : Rcpp
hello <0x100843178>
NULL


but, If I use this file instead:

=====================
#include <Rcpp.h>

using namespace Rcpp;

SEXP foo_( IntegerVector x ) ;

extern "C" {
	SEXP foo ( SEXP x ){ return foo_(x) ; }
}

SEXP foo_( IntegerVector x ) {
	Rprintf( "hello <%p> \n", x.asSexp() ) ;
	return x ;
}
=====================

it works:

romain at naxos /tmp $ Rscript test.R
Le chargement a nécessité le package : Rcpp
hello <0x102cc0cd8>
  [1]  1  2  3  4  5  6  7  8  9 10


In the first case, we are still able to determine the correct function, 
otherwise it would not print anything but the object is not correctly 
passed through.

Any ideas ?

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5



More information about the Rcpp-devel mailing list