[R] library.dynam

Murat Tasan mmuurr at gmail.com
Tue Jan 26 23:16:11 CET 2010


hi, i'm having some trouble getting a package to load a shared library
object in .onLoad(...)

i have a shared object file, say "mylib.so".

if i start an R session, and via the CLI specify the actual library
via:
> dyn.load("mylib.so")
everything works quite well (i.e. i can then follow with some .Call
(...) methods)

now, i'd like to include this shared library in my package.
assume that the .c file has already been compiled and i have the .so
file at some PATH.
in my zzz.R file i include:

.onLoad <- function(libname, pkgname) {
  library.dynam("mylib", lib.loc = PATH)
}

when i load the package, however, i get:

Error in .find.package(package, lib.loc, verbose = verbose) :
  there are no packages called 'RCurl', 'bitops', 'rjson', 'stats',
'graphics', 'grDevices', 'utils', 'datasets', 'methods', 'base'

so it appears i need to specify the package name, so if i change the
call to:

  library.dynam("mylib", pkgname, lib.loc = PATH), i get:

Error in .find.package(package, lib.loc, verbose = verbose) :
  there is no package called 'mypackage'
Error : .onLoad failed in 'loadNamespace' for 'mypackage'

which makes sense because the package namespace isn't attached yet.
so i'm not really sure what to specify for the package parameter of
library.dynam.

i've elected to try to use library.dynam() instead of useDynLib() in
the NAMESPACE file because this is a VERY customized package and the
library i'm using will change often enough and will probably be placed
in a non-standard location on the user's system.

ideas?



More information about the R-help mailing list