[R] how to save an R object selectively?

Rolf Turner r.turner at auckland.ac.nz
Mon Aug 11 23:01:43 CEST 2008


On 11/08/2008, at 9:57 PM, carol white wrote:

> Thanks for your replies.
>
> So there is no way to add one or more objects to the existing  
> objects stored in .RData?

	Not really.  There is no ``append=TRUE'' argument for save().

	There is a workaround, of course.  There [almost] always is in R:

		attach(".RData",warn.conflicts=FALSE)
		assign("clyde",clyde,pos=2)
		savepos(2)
		detach(2)

	where ``clyde'' is the object you are trying to ``save selectively''.

	***At this point*** the file .RData will contain the objects that  
were in it
	when you started your R session *and* ``clyde''.

	However, it could easily get mucked up.  In particular, if you were  
to answer
	``y'' to the question ``Save workspace image?'' when you quit,  
then .RData
	will get overwritten, and will then contain whatever objects were in  
your
	global environment at the time you quit.

	Hence I would ***STRONGLY ADVISE YOU NOT TO PROCEED IN THIS MANNER***.

	You are trying to use .RData in a way in which it was not intended  
to be used,
	and consequently tying yourself in knots.

	If you want to save objects selectively, save them in a different  
file from .Rdata,
	and then load or append (or dget()) that file, as I suggested in my  
previous email.

	Use the facilities of R in the way that they were intended to be  
used, rather than
	trying to force your own inappropriate paradigm upon R.  You'll find  
it more efficient
	to do things R's way rather than trying to force R to do things your  
way.  R gets
	it right.  [Almost] always!

		cheers,

			Rolf Turner

P. S.  ``Almost always'' == ``except on a set of measure/probability  
zero''.  :-)

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}



More information about the R-help mailing list