[R] library.dynam

Murat Tasan mmuurr at gmail.com
Tue Jan 26 23:25:33 CET 2010

to clarify the example a bit, assume that for lib.loc i always want to
search the current working directory of the R session (thus forcing
the user to have mylib.so sitting in the directory returned by getwd()
when loading the package).

NOTE: this is not how i will finally implement this package, but is a
temporary requirement for my writing this package for some colleagues.

On Jan 26, 5:16 pm, Murat Tasan <mmu... at gmail.com> wrote:
> 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?
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list