Re: [Rd] Shared routines in a dynamic library.

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 30 Jul 2012 21:36:06 +0100

On 30/07/2012 14:48, David L Lorenz wrote:
> All,
> I have a question about referring to a subroutine that is in a dynamic
> library other than the one in my current package.
> Let's say that I have a package foo and it has some FORTRAN code that
> contains the subroutines foo1 and foocommon. The package foo has an R
> function that calls foo1 and foocommon is a subroutine that is called from
> foo1.
> And, I have another package called bar which also has some FORTRAN code
> that contains the subrouting bar1. But bar1 also calls foocommon. The bar
> package is distinctly different from foo, but would require foo (even if
> the FORTRAN code did not have the common subroutine).
>
> I can think of a few ways to resolve this.
> 1. Place a copy of foocommon.f into the shared library for bar.
> 2. Put all of the FORTRAN code into the foo package and just rely on the R
> code in bar to call the code that it needs.
> 3. Refer to the shared library in the bar package. I assume that I'd do
> this in the NAMESPACE file using useDynLib(foo) in addition to
> useDynLib(bar), but I found no reference to it in Writing R extensions.
> Is there a recommended way to solve this issue? Thanks.

See
http://cran.r-project.org/doc/manuals/R-exts.html#Linking-to-other-packages . It is the main recommendation (and none of the above).

If bar loads foo, you can access things in foo's DLL by e.g. .C("bah", PACKAGE="foo"). foo's DLL must be loaded so (3.) is not relevant. But that is dangerous (foo might change) and will be noted by R CMD check.

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 30 Jul 2012 - 20:39:56 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 31 Jul 2012 - 11:30:35 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.

list of date sections of archive