*“I recommend that you default to S3.” - Hadley Wickham
** Maybe use S7 instead?
print(), summary(), plot(), predict(), etc.$| S3 | S4 | S7 | R6 | |
|---|---|---|---|---|
| Package | base R | base R | S7 | R6 |
| OOP type | Functional | Functional | Functional | Encapulated |
| Complexity | Low | High | Medium | High |
| Payoff | Low | High | High | High |
| Team size | Small | Large | Large | Small-large |
| Namespace | Global | Global | Global | Local |
| Modify in place | No | No | No | Yes |
| Method chaining | |> |
|> |
|> |
$ |
| Get/set | $ |
@ |
@ |
$ |
| Create class | function() |
setClass() |
new_class() |
R6Class() |
| Create validator | function() |
setValidity() | setClass(validator = f()) |
new_class(validator = f()) |
$validate() |
| Create generic | UseMethod() |
setGeneric() |
new_generic() |
NA |
| Create method | g.y <- function() |
setMethod() |
method() |
R6Class() |
| Create object | class(x) <- "y" |
new() |
x <- class_y() |
$new() |
| Additional components | attributes | slots | properties | fields & methods |