[Rcpp-devel] [Rd] Sections 5.8.1 and 5.8.2 of Writing R Extensions (LinkingTo)

Dominick Samperi djsamperi at gmail.com
Wed Oct 27 21:17:24 CEST 2010


On Wed, Oct 27, 2010 at 2:43 PM, Simon Urbanek
<simon.urbanek at r-project.org>wrote:

>
> On Oct 27, 2010, at 1:22 PM, Dominick Samperi wrote:
>
> > Hello,
> >
> > In Sections 5.8.1 and 5.8.2 of Writing R Extensions the following pattern
> is
> > suggested
> > for getting the path to a file in another package:
> >
> > PKGB_PATH=Œecho ‚library(packB); cat(system.file("libs",
> package="packB"))‚
> > \
> > | ${R_HOME}/bin/R --vanilla --slaveŒ
> >
> > Is the library(packB) really needed here?
>
> Not that I'm aware of - it's just a check that that package can be used. If
> you omit it you will get an empty string and no error on failure.
>

I did not tell the whole story here. Assume the packB depends on packC in
the sense that packB.dll links to packC.dll.
Then library(packB) will trigger library(packC), and this appears to have
the side effect of eliminating the need to place
the directories containing packB.dll and packC.dll on the search path.

If the library(packB) is not used in this situation there will be a failure
if instead of
cat(sytem.file("libs", package="packB") one uses cat(packB:::getLibs()),
where packB:::getLibs() is defined by system.file("libs",package="packB").

The lesson here (for me) is that packB:::getLibs() has the side-effect of
loading packB.dll,
and this will fail if the OS cannot find packC.dll (so the directory
containing the latter would
have to be placed on the search path if library(packB) is not used above).

Dominick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101027/a36730df/attachment.htm>


More information about the Rcpp-devel mailing list