Re: [Rd] dyn.load and function calls without 'PACKAGE' argument

From: Duncan Temple Lang <duncan_at_wald.ucdavis.edu>
Date: Fri 08 Dec 2006 - 17:15:48 GMT

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jhallman@frb.gov wrote:
> I'm writing a package that interfaces to the FAME database, via a
> library of compiled C routines accessible through a Linux .so file. My
> .onLoad() function loads the .so like this:
>
> dyn.load("/opt/fame/timeiq/lib/linux_x86/libjchli.so", local = F)
>
> and after that I also load my own fame.so via
>
> library.dynam("fame", package = "fame")
>
> The code in fame.so uses functions found in libjchli.so, making the
> 'local = F' argument in dyn.load() necessary.

Well, that is one approach.
A more regular and in most senses "better" approach is to have your fame.so link against libjchli.so when creating the fame.so DLL/SO. Then you don't have to pollute the global symbol table for the process with libjchli.so and you can use the PACKAGE argument.

That said, the PACKAGE argument is not necessary if you use a NAMESPACE file for the package.
Load the fame.so with useDynLib() in the NAMESPACE file and not library.dynam()

And if you explicitly list the routines you want to use in the useDynLib() call, you can refer to them as   .Call(foo, ...)

with no quotes, no PACKAGE and you will be able to handle multiple versions and provide aliases for the routine names.

> But since Fame symbols
> are found in libjchli.so, which is NOT part of my package, I can't, for
> example, do this:
>
> .C("cfmfin", status = integer(1), PACKAGE = "fame")
>
> since the PACKAGE argument tells R to look only in fame.so for symbols.
> Instead, I have to do it without specifying 'PACKAGE', i.e.,
>
> .C("cfmfin", status = integer(1))
>
> This works, but 'R CMD check' complains:
>
> "Foreign function calls without 'PACKAGE' argument:"
>
> followed by a list of the functions called from libjchli.so.
>
> Is there a way to make R CMD check happy here?
>
> Jeff
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

iD8DBQFFeZ3E9p/Jzwa2QP4RAoJ5AJsFZAFVuvmoEWhKFWxmncbHTLtpgwCfT84w eN2RaXPav1/8erL08urKxT0=
=NksI
-----END PGP SIGNATURE-----



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Dec 09 09:20:12 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 08 Dec 2006 - 22:30:57 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.