Skip to content
Prev 41659 / 63424 Next

Writing new methods for `names<-`

On 11/02/2011 11:57 AM, Max Gasner wrote:
Hi Max --

'names<-' is already a generic

 > getGeneric("names<-")
standardGeneric for "names<-" defined from package "base"

function (x, value)
standardGeneric("names<-", .Primitive("names<-"))
<environment: 0x8f0a48>
Methods may be defined for arguments: x, value
Use  showMethods("names<-")  for currently available ones.

so write a 'replacement' method

setReplaceMethod("names", "my.dataset", function(x, value) {
     x at colnames <- value
     x
})

Hope that helps,

Martin