[R] .Rprofile, .First, and .RData

Martin Maechler maechler at stat.math.ethz.ch
Thu Feb 6 09:34:02 CET 2003


>>>>> "David" == David Richmond <daver969 at yahoo.com>
>>>>>     on Wed, 5 Feb 2003 22:45:04 -0800 writes:

    David> On Wednesday, February 5, 2003, at 09:30  PM, Henrik Bengtsson wrote:
    >> What do you have in .First() that you can not have directly in the
    >> .Rprofile script? For example:
    >> 

    David> Nothing that I can think of, but it's the principle
    David> of the thing. If i did have a reason to change
    David> .First, how would I do it ? More generally, suppose I
    David> want to ensure a variable is set to a certain value
    David> in .Rprofile, how can I be sure that .RData won't
    David> overwrite it? It just seems like loading .RData after
    David> .Rprofile makes it difficult to change things easily.

Setting global variables and relying on their values is always `un-clean'.
In your case, I would set options(): They can't ever be overridden by
any .RData -- e.g.,
     options(myABC = 1:3, myFile = "/abc/def")
and then use  getOption("myABC")
instead of a global variable named `ABC'.

BTW: I advocate not working with .RData at all. 
     I work with *.R scripts (using ESS) and when needed, explicit  
     save(.) and load(.) for a given list of objects and with
     filenames such as "foobar.rda" instead of ".RData".

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><




More information about the R-help mailing list