Skip to content
Prev 138355 / 398506 Next

renaming objects

On 4/03/2008, at 10:38 AM, Ericka Lundstr?m wrote:

            
That makes a new object --- which is precisely what the enquirer
	wanted ***NOT*** to do.

	That being said, I'm pretty sure that the answer to the original
	question ``Is there a way ... ?'' is ``No.''  The R-Core people
	will be able to provide a definitive answer, but it appears to me
	that the way a name is associated with an object is buried deep
	in the innards of R and is not accessible to the user.

	At this stage, I'd like to enquire ***why*** is it desired to
	be able to do this?  The one rationale that I can think of is the
	situation that x is so huge that it is impossible to make a copy
	of it (via ``y <- x'') without exceeding R's memory capacity.

	If x is not that huge, one can simply do ``y <- x'' and then
	``rm(x)'' and presto one has changed the object's name from ``x''
	to ``y''.

	I have written my own little utility function ``mv()'', imitating
	the Unix command ``mv'' to facilitate this:

	mv <- function (a, b) {
     		anm <- deparse(substitute(a))
     		bnm <- deparse(substitute(b))
     		if (!exists(anm,where=1,inherits=FALSE))
         		stop(paste(anm, "does not exist.\n"))
     		if (exists(bnm,where=1,inherits=FALSE)) {
         		ans <- readline(paste("Overwrite ", bnm, "? (y/n) ", sep =  
""))
         	if (ans != "y")
             	return(invisible())
     	}
     	assign(bnm, a, pos = 1)
     	rm(list = anm, pos = 1)
     	invisible()
	}

######################################################################
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com
######################################################################