Skip to content
Back to formatted view

Raw Message

Message-ID: <A5C9C326-7183-499C-B630-E64AC86910CE@gmail.com>
Date: 2009-02-20T23:32:58Z
From: Fuchs Ira
Subject: 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")
}