Q:

using attributes() inside function

I need a function like this:  
note<-function(object,text=""){attributes(object)[4]<-text}  

eg: note(xxx,"yyyy") 
in which I try to set to the value "yyyy" the fourth attribute of xxx object (in the global  env). As it is, the function (as expected) doesn't work because it modifies the value in the
function env.
Any suggestion?

A:

You could make the function return the object itself, so it can be re-assigned:
note <- function(object, text = "") {
    attributes(object)[4] <- text
    return(object)
}

xxx <- note(xxx, "yyyy")

