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

Chris Jefferson chris at bubblescope.net
Wed May 29 15:42:55 CEST 2013


On 29/05/13 14: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"
>
> I swear the only thing I changed was the function name. Hence my question:
> Are there any restrictions I am unaware of?

Without seeing your changed code, it is hard to know which case you 
missed. I have certainly changed the names exported, without problem.
Make sure you consistently change the name:

In the source file (cpp)
In the header (.h)
In the .call statement

Check also what the 'exportPattern' is in NAMESPACE. It will probably 
look like:

exportPattern("^[[:alpha:]]+")

Which is fine, that just exports everything.

>
> 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



More information about the Rcpp-devel mailing list