[Rd] S3 - how to implement "colnames<-"
ccberry at ucsd.edu
Wed May 14 17:42:31 CEST 2014
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
`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`.
More information about the R-devel