0

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?

Community
  • 1
  • 1
alittleboy
  • 10,616
  • 23
  • 67
  • 107
  • Are you using `roxygen` to create your package? if so http://stackoverflow.com/questions/8407615/adding-usedynlib-through-roxygen – mnel Apr 09 '13 at 00:41
  • @mnel: thanks! I am using roxygen2. I read the post you mentioned, and it seems that @ useDynLib is the one to use. Please see the updated post above ;-) – alittleboy Apr 09 '13 at 01:08
  • @mnel: BTW, shall I use @ useDynLib Cdqrls? Thanks! – alittleboy Apr 09 '13 at 01:19
  • More likely `@useDynLib yourpackagename`, or `@useDynLib stats` if you want to use `Cdqrls` from the stats package.... – mnel Apr 09 '13 at 01:45
  • @mnel: thanks! I used @ useDynLib pkgname Cdqrls and it works now ;-) – alittleboy Apr 09 '13 at 02:42

1 Answers1

1

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.

alittleboy
  • 10,616
  • 23
  • 67
  • 107