nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
158 stars 24 forks source link

Incorrect C++ transpilation of package names containing dots #1332

Closed csbrown closed 11 months ago

csbrown commented 1 year ago

Issue Type:

Bug

Description:

When Nimble transpiles R code into C++ code, sometimes it does not correctly translate "." into "_dot_" when packages contain "." in the package name.

Minimal Reproducible Example:

nimbleFunction <- nimble::nimbleFunction

#' @export
example1 <- nimbleFunction(
  run = function(x = double(0)) { returnType(double(0))
    return(x)  
  }
)

#' @export
example <- nimbleFunction(
  run = function(x = double(0)) { returnType(double(0))
    return(example1(x)*x)
  })

1) Create a new package using devtools with a "." in the name, such as devtools::create("my.example") 2) Put the above code into an R file in the R directory 3) devtools::document() 4) Ensure that the NAMESPACE exports both example and example1 5) Ensure that the DESCRIPTION depends on nimble: Depends: nimble 6) devtools::install() the package 7) Restart R, and library("my.example") to import this code. 8) Try to compile the nimbleFunctions from your library

Expected Behavior:

The transpilation step should correctly find the "." in the package name and translate it to "_dot_" so that the package will successfully compile.

csbrown commented 1 year ago

Current workaround is to not use "." in your package name.

danielturek commented 1 year ago

Assigning to @perrydv

paciorek commented 11 months ago

@csbrown thanks for the report and careful reprex. Sorry for the delay in dealing with this. It will be fixed in next release (1.1.0) in the next few weeks.

Fixing this now on branch fix_1332. The issue is that the mangling we do in Rname2CppName for "." needs to be also done when we set up names for RCfunctions and nimbleFunctions, i.e., via labelFunctionMetaCreator. In looking at the transformations in Rname2CppName, I don't think any of the rest of the syntax is allowed in R package names.