I have an RcppEigen package that successfully Rcpp::sourceCpp()
s, devtools::check()
s, and devtools::document()
s, but I get the following error when I try to run a simple example:
Error in .Call("_pfexamplesinr_svolApproxLL", PACKAGE = "pfexamplesinr", :
"_pfexamplesinr_svolApproxLL" not available for .Call() for package "pfexamplesinr"
The error is generated from the following minimal piece of code
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)
This question suggests it might be a missing PKG_LIBS
in src/Makevars
, but my src/Makevars
says
## 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 =
Exactly what are you doing, and exactly what error do you get? It works here (apart from one warning):
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)$
I forked assuming it needed a fix; it doesn't look as if it requires one.
What may need adjusting is how you build the package and install it. I use some wrappers from my littler
package, but a plain R CMD INSTALL ...
will do too. I now sent you a trivial pull request to suppress the warning on idx
.
Edit: I see it now. You started from a plain package, not an Rcpp (or even RcppEigen package) so the NAMESPACE file is missing the dynLib()
entry, among other things.
Edit 2: Your NAMESPACE
was insufficient. The faster way is to just use the standard form as 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:]]+")
(The longer form generates the first three lines via roxygen2
; I am sure you can add this.)
Once that is done, your example runs:
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)$
I'll amend my PR to add this.