r-lib / cpp11

cpp11 helps you to interact with R objects using C++ code.
https://cpp11.r-lib.org/
Other
193 stars 46 forks source link

compilation fails when package name contains a period "." #275

Closed mkoohafkan closed 2 years ago

mkoohafkan commented 2 years ago

I am writing a collection of related packages named with the format <prefix>. as part of the package name (this is done in many other packages, e.g., see the assertive.* and aws.* package collections). Unfortunately, having a period . in the package name causes a problem during compilation:

v generated file 'cpp11.R'
v generated file 'cpp11.cpp'
Re-compiling ecyrm.drift
-  installing *source* package 'ecyrm.drift' ... (406ms)
   ** using staged installation
   ** libs
   g++  -std=gnu++11 -I"E:/R-4.2.0/include" -DNDEBUG  -I'E:/R-4.2.0/library/cpp11/include'   -I"E:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -UNDEBUG -Wall -pedantic -g -O0 -c cpp11.cpp -o cpp11.o
   cpp11.cpp:10:23: error: expected initializer before '.' token
      10 | extern "C" SEXP _ecyrm.drift_xy_to_mb(SEXP df) {
         |                       ^
   cpp11.cpp:17:23: error: expected initializer before '.' token
      17 | extern "C" SEXP _ecyrm.drift_mb_to_xy(SEXP df) {
         |  
...

The . in the package name prefix is interpreted as a token in the generated C++ wrapper code.

Is there a way for cpp11 to support . in package names when writing the extern C wrappers in cpp11.R? One thought is substituting the . for _ in the C++ code, but note that _ is not an accepted character for R packages.