[R] Object and Classes ?

myshare mraptor at gmail.com
Fri May 15 02:07:22 CEST 2009


tried that does not seem to work, for me ? Always have to specify it fully :

someclass.blah(x)

On Wed, May 13, 2009 at 11:10 PM, Jeff Laake <Jeff.Laake at noaa.gov> wrote:
> class(x)="someclass"
>
> then blah(x)
>
> will invoke blah.someclass
>
> Just look at all the example code in R.  For example summary.glm for
> summary(x) where x is of class glm.
>
>
> myshare wrote:
>>
>> I found a tutorial for creating classes using generic functions ? S3
>> way ! It was short description so I couldn't grok in full its
>> usage ... So far so good, what i currently do is something like this :
>>
>> Blah <- function(data,...)  UseMethod('Blah')
>>
>> Blah.default <- function( ...... ) {
>>   self = ....
>>   class(self) <- 'Blah'
>>   self
>>
>> }
>>
>> Blah.some_method <- function(self, .....) {
>>     self$abc ......and so on
>>
>> }
>>
>> My main "concerns" is now I have to call methods like this :
>>
>> Blah.some_method(obj,.....)
>>
>> isn't there some more shortcut syntax something along the lines
>> of  ;) :
>>
>> obj.some_method(...)
>>
>> Also if you can point me to some more documentation about using this
>> 'generic function' design in R.
>> >From what I saw there is also some R.oo class for building OOP like
>> interface, but it seems even more
>> cumbersome to use.
>>
>> Any link you can give me which discusses those concept in regards to
>> R, with examples too ;)
>> (Seems to me like a mix of javascript like prototyping with Perl bless
>> class name labeling,
>> like it much better than the rigid class oriented languages like Java ;) )
>>
>> PS>
>> One of the biggest hurdles with R is that the language name is one
>> character long and when you try to find some
>> docs or solutions google returns alot of garbage not related to R ;)
>> Otherwise I like very much the environment and the capabilities of the
>> package, just that I'm pretty new with all statistics terminology and
>> help pages are made for ppl who
>> understand statistics, but anyway it is very valuable tool for learning.
>>
>> ______________________________________________
>> 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