I read this basic question on renaming objects and @Shane 's answer to it, pointing me to lazy evaluation. Now I wonder if assign is evaluated lazily, too. Just like here:

assign("someNewName",someOldObject)
rm(someOldObject)

The reason why I wonder about this is the following use case: Assume I got 10K+ R objects each of which has two attributes called originalName and additionalName. Now I want to write a function that can efficiently let the user switch from one name to the other without losing these two attributes. Roughly like this...

EDIT: based on @Hadley's input I have changed my code.

switchObjectName <- function(x) {
  n1 <- attributes(x)$originalName
  n2 <- attributes(x)$additionalName
  objName <- deparse(substitute(x))
  if(objName == n1) {
    delayedAssign(n2,x,assign.env=.GlobalEnv)
  } else {
    delayedAssign(n1,x,assign.env=.GlobalEnv)
  }
  rm(list=c(objName),envir=.GlobalEnv)    
}

this works well, but I had quite some trouble to get the rm statement right. I tried rm(objName,envir=.GlobalEnv) but could not get it to work though objName is definitely a character cause it is the result of deparse(substitute(x).

Edit
Report