[R] Changing working directory

Martin Maechler maechler at stat.math.ethz.ch
Tue Apr 24 09:34:53 CEST 2007


>>>>> "Petr" == Petr Klasterecky <klaster at karlin.mff.cuni.cz>
>>>>>     on Mon, 23 Apr 2007 14:27:03 +0200 writes:

    Petr> Hi,
    Petr> you seem to have mixed 2 different things:
    Petr> 1) changing a working directory - see ?setwd, ?getwd
    Petr> However, this will NOT load another .Rdata file.

    Petr> 2) loading data - see ?load and ?save, ?save.image - loading new data 
    Petr> image will erase all currently stored objects.

Huuuh??? Not if you use the standard R function  load()!

Nothing is "erased".  If you load objects for which you have
objects in the same name in your workspace, then and only then,
those in the workspace will be replaced by the newly loaded
ones.

For that reason,

   attach("some_file.rda")

is sometimes preferred.
But, as Uwe Ligges has already said:
Working with .Rdata files is not recommended: You should work
with script files ("foo.R"), source() and possibly even own packages
and only save() {and load()/attach()} things that are expensive to rebuild.
And for those, I strongly recommend to use a filename different
from ".Rdata".

Martin Maechler, ETH Zurich

    Petr> Petr


    Petr> Walter Paczkowski napsal(a):
    >> Good morning,
    >> 
    >> I keep copies my .RData file in different directories for different projects on Windows XP.  There is an icon on my desktop for each project so all I have to do is click on the icon to open R for a specific project, i.e. a specific .RData file.  How do I change to another .RData file from within R without first closing R?
    >> 
    >> Thanks,
    >> 
    >> Walt Paczkowski



More information about the R-help mailing list