[Rcpp-devel] Are there any C++ function name restrictions?

Dirk Eddelbuettel edd at debian.org
Wed May 29 16:05:51 CEST 2013


Hi Asis

On 29 May 2013 at 15:20, Asis Hallab wrote:
| Dear Rcpp Experts,
| 
| hopefully this question of mine is not too stupid.
| 
| Well, I am a greenhorn with Rcpp and my C/C++ expertise is quite dusty.
| 
| I generated a new Rccp package and changed the hello_world function.
| The attached Rcpp Code stops working if I rename the method
| "rcpp_hello_world" to
| "conditionalProbabilityTables". The error I get is:
| "conditionalProbabilityTables" not available for .Call() for package "PhyloFun"

You must have missed some update somewhere. It is impossible to tell from
what you posted below because you eg did not show a) how your library is
loaded (via file NAMESPACE ?) and b) how R calls you C function.

I think you are doing it right going "long form" via the .h, .cpp and .R
files and creating a package.  But you altered one thing (adding OpenMP) so I
would suggest to retreat, start over from Rcpp.package.skeleton() and then
change the Rcpp.help.world identifier (or add a second one?) in the header
file, the source file and the R file calling it.

Dirk

| 
| I swear the only thing I changed was the function name. Hence my question:
| Are there any restrictions I am unaware of?
| 
| I searched the web for "rcpp function name restrictions" and such, but
| could not find anythig related.
| 
| The Rcpp Code I generated with Rcpp.package.skeleton( name="PhyloFun" )
| 
| //
| // Header File:
| //
| #ifndef _PhyloFun_pp_RCPP_HELLO_WORLD_H
| #define _PhyloFun_pp_RCPP_HELLO_WORLD_H
| 
| #include <Rcpp.h>
| #ifdef _OPENMP
|    #include <omp.h>
| #else
|    #define omp_set_num_thread(x) 1
| #endif
| 
| RcppExport SEXP rcpp_hello_world( SEXP uniqueEdgeLengths, SEXP annos, SEXP
|     stringifiedAnnotations, SEXP annotsMutationProbTableList, SEXP
|     mutTblLengthColIndx, SEXP pMutColIndx, SEXP unknownAnnot, SEXP nThreads ) ;
| 
| #endif
| 
| //
| // CPP File
| //
| #include "rcpp_hello_world.h"
| 
|     // CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
|     // NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
|     // List z            = List::create( x, y ) ;
|     //
|     // return z ;
| SEXP rcpp_hello_world( SEXP uniqueEdgeLengths, SEXP annos, SEXP
|     stringifiedAnnotations, SEXP annotsMutationProbTableList, SEXP
|     mutTblLengthColIndx, SEXP pMutColIndx, SEXP unknownAnnot, SEXP nThreads ){
|     using namespace Rcpp ;
| 
|   BEGIN_RCPP
|     NumericVector numberThreads = NumericVector( nThreads );
|     omp_set_num_threads( numberThreads(0) );
| 
|     NumericVector edgeLengths = NumericVector( uniqueEdgeLengths );
|     List cpts = List();
| 
|     #pragma omp parallel for
|     for ( int i = 0; i < edgeLengths.size(); i++ )
|     {
|       // NumericVector cpt = conditionalProbabilityTable( edgeLengths( i ),
|       //     annos, stringifiedAnnotations,  annotsMutationProbTableList,
|       //     mutTblLengthColIndx,  pMutColIndx,  unknownAnnot );
|       // Named cptListEntry = Named( edgeLengths( i ) );
|       // cptListEntry = cpt;
|       NumericMatrix cpt = NumericMatrix( 1000, 1000 );
|       cpts.push_back( cpt );
|     }
|     return( wrap( cpts ) );
|   END_RCPP
| }
| 
| //
| // Makevars
| //
| PKG_CXXFLAGS="-fopenmp"
| PKG_LIBS=$(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()")
| $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -fopenmp
| 
| Help will be much appreciated!
| Cheers!
| _______________________________________________
| 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

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list