问题
I am trying to follow closely the directions in the Rcpp package documentation, but I am getting the error
Error in .Call("MicroCreditLRVBR_TestJacobian", PACKAGE = "MicroCreditLRVBR") :
"MicroCreditLRVBR_TestJacobian" not available for .Call() for package "MicroCreditLRVBR"
The package framework was built with Rcpp.package.skeleton()
. I copied in my R
and C++
code, modified the Makevars
to point to some code outside the package, updated the DESCRIPTION
to link to RcppEigen
, and ran compileAttributes()
. I then ran R CMD build
to create a .gz
file and R CMD INSTALL
to install it. It built and linked successfully, but terminated with the above error.
I can see that the function MicroCreditLRVBR_TestJacobian
is indeed defined in RcppExports.cpp
and RcppExports.R
. I don't know why it is not available for .Call
.
Note that NAMESPACE
includes useDynLib(MicroCreditLRVBR)
and exportPattern("^[[:alpha:]]+")
.
A public copy of the package in its current state is in this github repo. Any help would be appreciated.
回答1:
When you switched the name from:
MicroCreditLRVB
to
MicroCreditLRVBR
You forgot to modify the package name in the NAMESPACE file
e.g.
useDynLib(MicroCreditLRVB)
goes to:
useDynLib(MicroCreditLRVBR)
Also, remove lines 1-22 from microcredit_stan_lib.R. They should be put into a "demo" file found within the /inst
.
Lastly, import boost headers using the BH
and cut down on the absolute paths within the Makevars
.
回答2:
The problem was resolved by removing the line
jac_test <- TestJacobian()
from the file microcredit_stan_lib.R
.
For future reference, I had a C++ file in src/
that defined
// [[Rcpp::export]]
Rcpp::List TestJacobian() {
... do stuff ...
}
..and a library file R/microcredit_stan_lib.R
that had a line in the outermost environment
jac_test <- TestJacobian()
By commenting out jac_test <- TestJacobian()
, the problem was resolved. I'm not sure why.
来源:https://stackoverflow.com/questions/37336916/function-not-available-for-call-using-rcpp-package-skeleton-and-compileattrib