[R] Learning S3

Henrik Bengtsson hb at stat.berkeley.edu
Thu Jun 18 18:35:32 CEST 2009


Not a suggestion on documentation, but to ease S3 coding and hiding
some of the details, you might want to consider the R.methodsS3
package.  It basically provides some S3 code generators and makes it
clear what class of objects a method is dispatched on.  From the
example code:

setMethodS3("foo", "default", function(x, ...) {
  cat("In default foo():\n");
  print(x, ...);
})

setMethodS3("foo", "character", function(x, ...) {
  cat("In foo() for class 'character':\n");
  print(x, ...);
})

# The generic function is automatically created!
print(foo)

foo(123)
foo("123")

My $.02

/Henrik



On Thu, Jun 18, 2009 at 9:16 AM, Gabor
Grothendieck<ggrothendieck at gmail.com> wrote:
> There is a section on Object Orientation in MASS (I have 2nd ed).
>
> On Thu, Jun 18, 2009 at 12:06 PM, Hadley Wickham<hadley at rice.edu> wrote:
>> Hi all,
>>
>> Do you know of any good resources for learning how S3 works?  I've
>> some how become familiar with it by reading many small pieces, but now
>> that I'm teaching it to students I'm wondering if there are any good
>> resources that describe it completely, especially in a reader-friendly
>> way.  So far I've found:
>>
>>  * http://cran.r-project.org/doc/manuals/R-lang.html#Object_002doriented-programming
>> - it has most of the theory (although some bits are missing), but no
>> examples
>>
>>  * page 33 of http://CRAN.R-project.org/doc/Rnews/Rnews_2004-1.pdf
>> shows how to create a simple object in both S3 and S4
>>
>> What has helped you learn S3?
>>
>> Regards,
>>
>> Hadley
>>
>> --
>> http://had.co.nz/
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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