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

Hadley Wickham hadley at rice.edu
Tue Feb 15 19:49:14 CET 2011


> 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 of x with
> new names, rather than trying to modify the original.

And for that task, you might find setNames useful: "It is most useful
at the end of a function definition where one is creating the object
to be returned and would prefer not to store it under a name just so
the names can be assigned."

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list