s3_dispatch: Illustrate S3 dispatch

Description Usage Arguments Examples

Description

s3_dispatch() prints a list of all possible function names that will be considered for method dispatch. There are four possible states:

Learn more at https://adv-r.hadley.nz/s3.html.

Usage

1

Arguments

call

Example call to S3 method

env

Environment in which to evaluate call

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
x <- Sys.time()
s3_dispatch(print(x))
s3_dispatch(is.numeric(x))
s3_dispatch(as.Date(x))
s3_dispatch(sum(x))

# Internal vs. regular generic
x1 <- 1
x2 <- structure(2, class = "double")

my_length <- function(x) UseMethod("my_length")
s3_dispatch(my_length(x1))
s3_dispatch(my_length(x2))

length.double <- function(x) 10
s3_dispatch(length(x1))
s3_dispatch(length(x2))

sloop documentation built on May 1, 2019, 10:30 p.m.