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

Martin Maechler maechler at stat.math.ethz.ch
Wed May 14 11:53:09 CEST 2014


DO *NOT*  post to both R-help and R-devel !!
That is considered *very* impolite.

As this is a question for R-help  only, i.e., not fit for
R-devel anyway :

>>>>> Witold E Wolski <wewolski at gmail.com>
>>>>>     on Wed, 14 May 2014 10:57:09 +0200 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.

This is not easily possible, as `colnames<-` is *not* a generic
function.  OTOH, this is not necessary either, as
colnames, rownames are basically just short cuts for dimnames anyway:

As  `dimnames<-` *is* a generic function, 
so you write methods for `dimnames<-`.

Martin

    > -- 
    > Witold Eryk Wolski

    > [[alternative HTML version deleted]]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Hmm,...



More information about the R-help mailing list