[R] loading shared libraries at startup

Faheem Mitha faheem at email.unc.edu
Tue Mar 13 04:14:53 CET 2001



On Mon, 12 Mar 2001, Thomas Lumley wrote:

> On Mon, 12 Mar 2001, Faheem Mitha wrote:
> 
> > Dear people,
> >
> > I compiled a bit of C code into a shared library cftpR.so, and load it
> > into R at runtime using
> >
> > > dyn.load("cftpR.so")
> >
> > This works fine, however when I put
> >
> > .First <- function()
> > {
> > dyn.load("/home/faheem/research/cftp/cftpR.so")
> > }
> >
> > (using absolute path names; also tried with just dyn.load("cftpR.so")),
> > into my .Rprofile to load the library at startup, the library doesn't get
> > loaded. I am sure I am missing something obvious, but I spent a while
> > trying different things and reading documentation, but no dice. So, I
> > crave your indulgence.
> 
> It works when I do it.
> 
> aleph% more .Rprofile
> .First<-function(){
>   print(".First is being run")
>   dyn.load("~/Rarchive/libloc/survival5/libs/survival5.so")
>   print(is.loaded(symbol.C("coxdetail")))
> }
> aleph% R
> ...
> 
> [Previously saved workspace restored]
> 
> [1] ".First is being run"
> [1] TRUE
> 
> What are the symptoms: do you get an error message? How do you tell it
> wasn't loaded? Is .First() being run?

I added a couple of lines to my .First as you did above.

faheem ~>cat .Rprofile

print("reading .Rprofile")
.First <- function()
{ 
print(".First is being run")
dyn.load("/home/faheem/research/cftp/cftpR.so")
print(is.loaded(symbol.C("onestepupdateR")))
}

but when I run R I just get

[1] "reading .Rprofile"
[Previously saved workspace restored]

> 

Seems to be ignoring .First completely. It worked fine with previous
versions of R (I used to use it to load libs). Can you suggest some
debugging diagnostics? Is this perhaps due to some old .Rdata files
floating around or something like that?

You asked how I know that it wasn't loaded. Well, this is probably not the
best way, but I simply do

> dyn.unload("cftpR.so")
Error in dyn.unload(x) : shared library
"/home/faheem/research/cftp/cftpR.so" was not loaded
> 

If it is already loaded, it unloads without comment. I'm using R 1.2.1
(SuSE Linux 6.2). Recompiled it using gcc version egcs-2.91.66.

                                             Faheem.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list