[R] Error when modifying names of the object returned by get()

2011-02-15 Thread John Edwards
I get the following error when I try to modify the names of the object returned by get(). Does anybody know how to do so? (I could use as.vector() to remove the names, but I'm interested in how to modify the object returned by get().) $ cat main_get_name_assign.R x=1:10 names(x)=letters[1:10]

Re: [R] Error when modifying names of the object returned by get()

2011-02-15 Thread Ista Zahn
Hi John, Probably there is a more elegent solution, but I usually do something like tmp - get(x) names(tmp) - letters[1:10] assign(x, tmp) rm(tmp) HTH, Ista On Tue, Feb 15, 2011 at 11:43 AM, John Edwards jhnedwards...@gmail.com wrote: I get the following error when I try to modify the names of

Re: [R] Error when modifying names of the object returned by get()

2011-02-15 Thread Duncan Murdoch
On 15/02/2011 11:43 AM, John Edwards wrote: I get the following error when I try to modify the names of the object returned by get(). Does anybody know how to do so? (I could use as.vector() to remove the names, but I'm interested in how to modify the object returned by get().) You can

Re: [R] Error when modifying names of the object returned by get()

2011-02-15 Thread Hadley Wickham
You can probably do this by constructing a call to the `names-` replacement function, but it's really bad style.  Don't write R code that has external side effects if you can avoid it.  In this case, you'll almost certainly get more maintainable code by writing your function to return a copy