[R] To improve my understanding of workspaces

Kevin E. Thorpe kevin.thorpe at utoronto.ca
Fri Mar 10 15:01:47 CET 2006


Thanks Adai.  A couple questions/comments about this.

Adaikalavan Ramasamy wrote:
> I use emacs and ESS to develop the scripts. The new releases of R has
> the script function already in built.

I use emacs and ESS too (in Linux).  I do not know about the script
function you mention.  It's not in my version (2.1.1) and I couldn't
find it in an RSiteSearch either.

> Typically I keep all the data and scripts related to a project in its
> own folder, so I have minimal worry about paths.

I do the same.

> To save large and associated objects, I use 
>    save(x, y, z, file="lala.rda", compress=TRUE) 
> and then to load x, y, z in another session or workspace I use
>    load("lala.rda") 
> 
> To save small dataframes and matrices, I use 
>    write.table(mat, file="lala.txt", sep="\t") 
> and to read it back I use
>    mat <- read.delim(file="lala.txt", row.names=1)

Am I correct that load() or read.<whatever>() or even data() will
bring the objects into the current workspace while attach() can
attach a save() data frame to the search path?  Is one approach
better than the other in general?

> 
> The problem with .RData (via quit or save.image), is that it keeps all
> intermediate objects which can be unnecessarily bloated and confusing.
> Further you will have difficulty distinguishing one .RData from the
> other by looking at the filename alone.

If you don't save the workspace on q(), do you also lose the history for
that session (although when working in emacs, this is rarely a problem)?

> Regards, Adai

Thanks again,

Kevin

> 
> 
> On Fri, 2006-03-10 at 06:58 -0500, Kevin E. Thorpe wrote:
> 
>>Hello.
>>
>>I have grown accustomed to the .Data directory in S-Plus and so when
>>I came to R I continued that behaviour by saving my workspaces at
>>the end of each R session.  So, I have saved workspaces in various
>>directories where I have used R just as I would have had various
>>.Data directories where I had used S-Plus.
>>
>>I have seen comments on the list, most recently from Prof. Ripley
>>that they don't routinely save their workspaces in this way.
>>So my questions are:
>>
>>   1. What do people do instead to manage projects?
>>   2. Is there an "official" recommendation?
>>
>> From my reading I have learned that you can save data frames
>>(and other objects?) to disk and then attach them.  Does this
>>save memory?  If I have read correctly, I understand that
>>everything in the workspace is in memory, but haven't been able
>>to determine if objects in the search path are as well.
>>
>>Kind Regards,
>>
>>Kevin
>>
> 
> 
> 


-- 
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Department of Public Health Sciences
Faculty of Medicine, University of Toronto
email: kevin.thorpe at utoronto.ca  Tel: 416.946.8081  Fax: 416.946.3297




More information about the R-help mailing list