Skip to content
Prev 241219 / 398500 Next

Adding meta-data when creating objects. e.g: changing "<-" so to (for example) add "creation time" - how-to and pros/cons?

Hi,

I have tried this (just to practice):
assign2 <- function(x, ...){
  assign(x, ..., envir=.GlobalEnv)
  attr(get(x, envir=.GlobalEnv), "creation.time") <- Sys.time()
}

assign2("y", 1:4)
Error in attr(get(x), "creation.time") <- Sys.time() :
   could not find function "get<-"

Why doesn't it work?
If I remove the attr() part,
identical(y, get("y")) returns TRUE, so why attr() cannot work with it?

Thanks in advance for the clarification,

Ivan


Le 11/11/2010 11:16, Michael Bedward a ?crit :

  
    

Thread (10 messages)