I got an error as the title shows
Error: object 'Cdqrls' not found
I use devtools
for building R packages, and one function in my current package, I used
.Call(Cdqrls, x[, id1, drop=FALSE] * w, w * z, epsilon)
and also includes a lm.c
file in the src
folder, which includes:
...
SEXP Cdqrls(SEXP x, SEXP y, SEXP tol)
{
SEXP ans, ansnames;
SEXP qr, coefficients, residuals, effects, pivot, qraux;
int n, ny = 0, p, rank, nprotect = 4, pivoted = 0;
double rtol = asReal(tol), *work;
...
directly copied from R source files. When I used load_all()
in devtools
, it compiles shared objects in src/ (I checked that works well) with new files: lm.o
and MyPkgName.so
. However, from the wiki of devtools
, I found that
load_all ignores the package NAMESPACE
If working properly, I think by running some functions, I am able to update the NAMESPACE
file to contain useDynLib(MyPkgName, Cdqrls)
. Is that correct? I think in that way the error may disappear... Any suggestions are greatly appreciated!
Update
According to @mnel and this post, it seems that using @useDynLib
should work. However, the function I used .Call()
is NOT documented, and there are several functions that used .Call
so I personally do not wanna document them as they're not used for end-users. Thus, where shall I put @useDynLib
?
The answer is to use @useDynLib PkgName Routine1 Routine2
using roxygen2, so that once running document()
function in devtools
the NAMESPACE file will contain useDynLib(PkgName,Routine1,Routine2)
, which will work perfectly.