From ccberry at ucsd.edu  Wed May 14 17:42:31 2014
From: ccberry at ucsd.edu (Charles Berry)
Date: Wed, 14 May 2014 15:42:31 +0000
Subject: [Rd] S3 - how to implement "colnames<-"
References: <CAAjnpdhA5zQD=Zjr1UL8ofTc6iBbCW3w1VWuidLdQHPsQ3PhBw@mail.gmail.com>
Message-ID: <loom.20140514T172447-280@post.gmane.org>

Witold E Wolski <wewolski <at> gmail.com> writes:

> 
> Have a class for which I would like to provide a "colnames<-.myclass"
> function so that
> 
> colnames(myintsance) <- c("a","b","c")
> can be called.


`colnames<-` is not generic as Luca noted.

But `dimnames<-` is.

If you write a suitable `dimnames<-.myinstance`, then `colnames<-` will 
find it.

`dimnames<-.data.frame` gives an example.

I think you will want to either call NextMethod() or replace
attr(x,"dimnames") and return x. That is, you probably do not want to
use `dimnames<-`inside `dimnames<-.myinstance`. 

HTH,

Chuck



[Rd] S3 - how to implement "colnames<-"
Charles Berry