Re: [R] autoloading .RData files / .Rhistory file

From: Duncan Murdoch <>
Date: Fri 17 Mar 2006 - 05:40:10 EST

On 3/16/2006 1:23 PM, Greg Tarpinian wrote:
> NOTE: WinXP, R2.2.0
> All,
> a while back I posted a question about using relative filereferencing.
> The responses have allowed me to successfully set up the following
> directory structure:
> ...\data\raw
> ...\data\derived
> ...\prog
> ...\lst
> ...\log

> In the \prog directory I have put an RGui.exe shortcut and "pointed it"
> at \prog as the "Start In" location. In the same directory I have
> created .Rprofile and .Renviron per the rw-FAQ. In \log I have created
> .Rhistory. .Renviron sets up several directory references that allow me
> to "point" R at the \lst, \log, \data\derived, and \data\raw directories
> without using full pathnames. My three questions:
> (1) Is it possible to have R use \data\derived as its default data
> storage location?

I think


would do that, but I'm not sure why you wouldn't want your .Rprofile and .Renviron files in the same place as the data, so I'm not sure I understand your goals.
> (2) Related to (1), what command(s) would I need to put in .Rprofile
> to get R to look in \data\derived and automatically load the
> xxx.RData file **when it exists** ?? [This is the only directory
> where an .RData file will ever be located; when an .RData file
> exists, there will only ever be one of them.]

if (file.exists(".RData")) load(file=".RData")

> Along these lines, it would be helpful to set R up so that when
> .RData does *not* exist, upon quitting Rgui.exe R will automatically
> save an xxx.RData file in the \data\derived directory.....

With the setwd() command above, that'll be the default location, but you'll have to agree to save it.
> (3) The .Rhistory file never seems to contain the command history of
> my session. It may be worthwhile to note that I always use an
> explicit save.image(file = ...) command and that upon exit I always
> decline to "Save Workspace Image?" since this is redundant. How
> can I get the .Rhistory file to capture the command history?

savehistory(file = ".Rhistory")

Depending on where you save it, it might not be loaded automatically; if you want to load it, use

loadhistory(file = ".Rhistory")

Duncan Murdoch

> Much thanks in advance for whatever help I might be able to obtain! I
> apologize if these are trivial questions.
> Kind regards,
> Greg
> ______________________________________________
> mailing list
> PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Fri Mar 17 06:04:55 2006

This archive was generated by hypermail 2.1.8 : Fri 17 Mar 2006 - 09:09:14 EST