Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Compilation fails when package name contain a "dot" and Rcpp function

Tags:

r

g++

rcpp

I am building a new package:

  • The package name contains a dot: for example my.package
  • The package exports one Rcpp function: for example rcppfunction

When I build the package using Rcmd INSTALL, compileAttributes is used behind the scene to automatically generate exported function,

RcppExport SEXP my.package_rcppfunction(...)

and I get a compilation error due to the dot in the exported name:

RcppExports.cpp:10:19: error: expected initializer before '.' token

As a workaround , I can change the package name to remove the dot from it , but I want better solution and to understand how the symbols are exported. So my question is:

  1. How can I parametrize the generated code to replace dot by a "_" for example (Maybe by giving some parameters to the export attribute) .
  2. Or How to change the g++ call to force it to compile such dotted symbols..

I don't know if this can help , but here my g++ call:

g++ -m32 -I"PATH_TO_R/R-30~1.2/include" -DNDEBUG    -
I"PATH_To_R/3.0/Rcpp/include" -
I"d:/RCompile/CRANpkg/extralibs64/local/include"     
-O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
like image 213
agstudy Avatar asked Dec 21 '13 15:12

agstudy


1 Answers

You can't do that -- the dot simply isn't allowed in a C or C++ function name:

Ie for

#include <stdlib.h>

int foo.bar(int x) {
    return(2*x);
}

int main(void) {
    foo.bar(21);
    exit(0);
}

we get

edd@max:/tmp$ gcc -c foo.c
foo.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
foo.c: In function ‘main’:
foo.c:9: error: ‘foo’ undeclared (first use in this function)
foo.c:9: error: (Each undeclared identifier is reported only once
foo.c:9: error: for each function it appears in.)
edd@max:/tmp$ 

and

edd@max:/tmp$ g++ -c foo.c
foo.c:4: error: expected initializer before ‘.’ token
foo.c: In function ‘int main()’:
foo.c:9: error: ‘foo’ was not declared in this scope
edd@max:/tmp$ 

In C++, foo.bar() is calling the member function bar() of object foo.

like image 101
Dirk Eddelbuettel Avatar answered Oct 19 '22 08:10

Dirk Eddelbuettel