RcppEigen package error: not available for .Call() for package

RcppEigen package error: not available for .Call() for package

我有一个 RcppEigen package 成功地 Rcpp::sourceCpp()s、devtools::check()s 和 devtools::document()s,但是当我尝试 运行 一个简单的例子:

Error in .Call("_pfexamplesinr_svolApproxLL", PACKAGE = "pfexamplesinr",  : 
  "_pfexamplesinr_svolApproxLL" not available for .Call() for package "pfexamplesinr"

错误是由以下最短代码产生的

devtools::install_github("tbrown122387/pfexamplesinr@cffe989")
numTime <- 3
numParts <- 500 # must agree with #define NP in likelihoods.cpp
u <- rnorm(numTime*(numParts+1))
params <- c(.9, 1, .1) # -1 < phi < 1, beta, sigma > 0
pfexamplesinr::svolApproxLL(rnorm(numTime), params, u)

suggests it might be a missing PKG_LIBS in src/Makevars, but my src/Makevars

## With Rcpp 0.11.0 and later, we no longer need to set PKG_LIBS as there is
## no user-facing library. The include path to headers is already set by R.
#PKG_LIBS = 

你在做什么什么,你得到什么什么错误?它在这里工作(除了一个警告):

edd@rob:~/git$ git clone git@github.com:eddelbuettel/pfexamplesinr.git
Cloning into 'pfexamplesinr'...
remote: Enumerating objects: 141, done.
remote: Counting objects: 100% (141/141), done.
remote: Compressing objects: 100% (82/82), done.
remote: Total 141 (delta 65), reused 120 (delta 44), pack-reused 0
Receiving objects: 100% (141/141), 46.75 KiB | 1.42 MiB/s, done.
Resolving deltas: 100% (65/65), done.
edd@rob:~/git$ cd pfexamplesinr/
edd@rob:~/git/pfexamplesinr(master)$ install.r
* installing *source* package found in current working directory ...
* installing *source* package ‘pfexamplesinr’ ...
** using staged installation
** libs
ccache g++  -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include'    -fpic  -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c RcppExports.cpp -o RcppExports.o
ccache g++  -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG  -I'/usr/local/lib/R/site-library/Rcpp/include' -I'/usr/local/lib/R/site-library/RcppEigen/include'    -fpic  -g -O3 -Wall -pipe -pedantic -Wno-misleading-indentation -Wno-unused -Wno-ignored-attributes -Wno-class-memaccess -c likelihoods.cpp -o likelihoods.o
In file included from likelihoods.cpp:2:
resamplers.h: In member function ‘void pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::resampLogWts(pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::arrayVec&, pf::resamplers::sys_hilb_resampler<nparts, dimx, num_hilb_bits, float_t>::arrayFloat&, const usvr&) [with long unsigned int nparts = 500; long unsigned int dimx = 1; long unsigned int num_hilb_bits = 5; float_t = double]’:
resamplers.h:1089:36: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1089 |         tmpPartics[i] = sortedParts[idx];
      |                         ~~~~~~~~~~~^
ccache g++ -std=gnu++14 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -o pfexamplesinr.so RcppExports.o likelihoods.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-pfexamplesinr/00new/pfexamplesinr/libs
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (pfexamplesinr)
edd@rob:~/git/pfexamplesinr(master)$ 

假设它需要修复,我分叉了;看起来好像不需要一个。

可能需要调整的是构建和安装包的方式。我使用了我的 littler 包中的一些包装器,但普通的 R CMD INSTALL ... 也可以。我现在向您发送了一个简单的拉取请求,以抑制 idx.

上的警告

编辑:我现在看到了。您从普通包开始,而不是 Rcpp(甚至 RcppEigen 包),因此 NAMESPACE 文件缺少 dynLib() 条目等。

编辑 2: 您的 NAMESPACE 不够。更快的方法是只使用标准形式 e.g. here

useDynLib(pfexamplesinr)
import(RcppEigen)
importFrom(Rcpp, evalCpp)

## export all regularly named functions
## (but allow for private functions whose name starts with a dot).name <- function(...)
exportPattern("^[[:alpha:]]+")

(较长的表格通过 roxygen2 生成前三行;我相信您可以添加它。)

完成后,您的示例将运行:

edd@rob:~/git/pfexamplesinr(master)$ cat /tmp/test.R 
library(pfexamplesinr)
numTime <- 3
numParts <- 500
u <- rnorm(numTime*(numParts+1))
params <- c(.9, 1, .1) # -1 < phi < 1, beta, sigma > 0
svolApproxLL(rnorm(numTime), params, u)
edd@rob:~/git/pfexamplesinr(master)$ Rscript /tmp/test.R 
[1] -4.98311
edd@rob:~/git/pfexamplesinr(master)$ 

我将修改我的 PR 以添加此内容。