} else if (is.logical(x)) { !x } else if (is.character(x)) { str_reverse(x) } else if (is.factor(x)) { levels(x) < - rev(level(x)) x } else { stop("Not supported") } } Why do we need OOP? This is even more important for functions in base R, like print()
class_logical) < - function(x) { !x } method(bizarro, class_character) < - function(x) { str_reverse(x) } Then we de fi ne methods Name of the generic Built-in class
validator = function(self) { if (length(self@start) ! = 1) { "@start must be length 1" } else if (length(self@end) ! = 1) { "@end must be length 1" } else if (self@end < self@start) { "@end must be greater than or equal to @start" } } ) Can add a validator to prevent that from happening