Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
new_player <- function(name, points) { p <- list(name = name, points = points) class(p) <- "player" p } describe <- function(obj) { UseMethod("describe") } describe.player <- function(obj) { paste(obj$name, "has", obj$points, "points") } describe.captain <- function(obj) { paste(obj$name, "is the team captain") } john <- new_player("John", 45) jenny <- new_player("Jenny", 60) class(jenny) <- c("captain", "player") describe(john) describe(jenny) jenny$points
[1] "John has 45 points"
[1] "Jenny is the team captain"
[1] 60