nCompiler icon indicating copy to clipboard operation
nCompiler copied to clipboard

dependent package doen't work if `nCompiler` is in `imports`

Open paciorek opened this issue 3 months ago • 0 comments

So I tested creating a 'user' package that has nCompiler in imports in DESCRIPTION and import(nCompiler) in NAMESPACE.

In this situation, nCompiler is not on the search path, and we get this:

> library(testpkg)
> myfun()
To-do: Care needed to filter interfaced methods by exportMembers names.
Error in as.environment("package:nCompiler") : 
  no item called "package:nCompiler" on the search list
> traceback()
6: .Call(<pointer: 0x73e391c13a10>)
5: newCobjFun()
4: initializeCpp(CppObj)
3: initialize(...)
2: Cnc$new()
1: myfun()

Here's what myfun looks like, though I think things are clear from the above.

myfun <- function(x) {
    nc <- nClass(
        Rpublic = list(
            Rv = NULL,
            Rfoo = function(x) x+1
        ),
        Cpublic = list(
            Cv = 'numericScalar',
            Ca = 'numericVector',
            Cfoo = nFunction(
                fun = function(x) {
                    return(x+1)
          },
          argTypes = list(x = 'numericScalar'),
          returnType = 'numericScalar')
        )
    )
    Robj <- nc$new()
    Cnc <- nCompile(nc)
    Cobj <- Cnc$new()

    return(Cobj$Cfoo(x))
}

paciorek avatar Jan 16 '26 19:01 paciorek