Skip to content
Prev 171244 / 398506 Next

how to add names to an object created using assign

If I assign a variable in a function, as in:

test=function(){
assign("a",c(1,2,3),env=.GlobalEnv)
}

How can I do the equivalent of:

names(a)=c("one","two","three")

within the function?

Merely adding the call to names does not work within the function as  
it only affects a local variable:

test=function(){
assign("a",c(1,2,3),env=.GlobalEnv)
names(a)=c("one","two","three")
}