[R] loading shared libraries at startup

Faheem Mitha faheem at email.unc.edu
Tue Mar 13 19:21:29 CET 2001



On 13 Mar 2001, Peter Dalgaard BSA wrote:

> Faheem Mitha <faheem at email.unc.edu> writes:
> 
> > 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?
> 
> If there's *another* .First in your workspace, it would seem to
> explain the behaviour. What is in .First after loading?

Yes, indeed there seems to be (presumably saved in the old .Rdata)

> .First
function()
{ library(mva)
}
> 

This is what I had before I changed it. I just looked at the help page for
Startup. It says

              **********************************

Then, unless --no-init-file was given, R searches for a file called
`.Rprofile' in the current directory or in the user's home
directory (in that order) and sources it into the user workspace. 

It then loads a saved image of the user workspace from `.RData' if there
is one (unless --no-restore-data was specified, or
--no-restore).

Finally, if a function .First exists, it is executed as .First().

                *********************************

This seems to suggest that (if I am understanding it correctly), that even
if a .First is present in the .Rprofile, it will be overwritten by a copy
of .First if such a copy is saved in .Rdata. Therefore, when the .First is
executed, it will be the version saved in .Rdate.

But isn't this undesirable behavour? Ie. isn't the preferred version of
First the one in .Rprofile? What is the best way of dealing with this? Do
I need to remove .First from my environment every time I change .First in
my .Rprofile? A preemptive line in .Rprofile like

rm(".First")
.First <- function()
...

perhaps? Thanks for the clarification. Funny, I never noticed this
behaviour before, though, and I have changed .First quite a lot in the
past. Oh, I see, the following would explain it:

"Prior to R version 1.2.1, `.Rprofile' was sourced after `.RData' was
loaded, although the documented order was as here."

"Here" presumably means as stated above, ie. first .Rprofile then .Rdata,
so documented order and actual order were different before 1.2.1? The
(actual) original order seems preferable to me, though.

                                                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