foo <- new_generic("foo", "x")
method(foo, class_integer) <- function(x) "integer"
method(foo, class_missing) <- function(x) "missing"
method(foo, class_any) <- function(x) "fallback"
foo(1)
foo()
foo("x")
Run the code above in your browser using DataLab