[R] S3 - how to implement "colnames<-"

Luca Cerone luca.cerone at gmail.com
Wed May 14 11:42:02 CEST 2014


Hi Witold,
you should first of all redefine colnames to use UseMethod.
Then you have to write a colnames.default that uses base::colnames
(so that it does not interfere with existing code and other functions)
and the you can define the method for your class.

I would suggest, though, to use attributes for your object, rather
than risking to mess up the default R function.

Hope it helps,
Cheers,
Luca

2014-05-14 10:57 GMT+02:00 Witold E Wolski <wewolski at gmail.com>:
> 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.
>
> Witold
>
>
> --
> Witold Eryk Wolski
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Luca Cerone

Tel: +34 692 06 71 28
Skype: luca.cerone



More information about the R-help mailing list