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

William Dunlap wdunlap at tibco.com
Wed May 14 18:47:13 CEST 2014


The last argument of a replacement function (one used on the left side
of an assignment) must be called 'value'.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, May 14, 2014 at 8:38 AM, Witold E Wolski <wewolski at gmail.com> wrote:
> Hi
>
> So how would I actually implement it - what is the signature?
>
>
> "dimnames<-.myclass" <- function(data,newnames){
> colnames(data) = newnames
> return(data)
> }
>
> ?
>
>
>
> On 14 May 2014 11:53, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>
>> 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,...
>>
>
>
>
> --
> 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.



More information about the R-help mailing list