
Coerce a tbl_now with another package's generic
tbl_now_coercion_methods.RdThese S3 methods make each supported package's own coercion verb accept a
tbl_now. They are thin wrappers around the matching tbl_now_to_*()
converter and are quiet by default.
as_epidist_linelist_data()(epidist) wrapstbl_now_to_epidist().as_epidist_aggregate_data()(epidist) wrapstbl_now_to_epidist()withformat = "aggregate".as_reporting_triangle()(baselinenowcast) wrapstbl_now_to_baselinenowcast()withformat = "matrix".as_tsibble()(tsibble) wrapstbl_now_to_tsibble().as.data.table()(data.table) wrapstbl_now_to_data_table().
Usage
# S3 method for class 'tbl_now'
as_epidist_linelist_data(data, ..., verbose = FALSE)
# S3 method for class 'tbl_now'
as_epidist_aggregate_data(data, ..., verbose = FALSE)
# S3 method for class 'tbl_now'
as_reporting_triangle(data, ..., verbose = FALSE)
# S3 method for class 'tbl_now'
as_tsibble(x, ..., verbose = FALSE)
# S3 method for class 'tbl_now'
as.data.table(x, ..., verbose = FALSE)See also
The tbl_now_to_*() functions these delegate to, which take the arguments:
tbl_now_to_epinowcast(), tbl_now_to_baselinenowcast(),
tbl_now_to_epidist(), tbl_now_to_tsibble(), tbl_now_to_data_table();
as_tbl_now() to come back the other way;
as_tibble() to drop to a plain tibble.
Examples
data(denguedat)
dengue <- tbl_now(denguedat[1:3000, ],
event_date = onset_week, report_date = report_week, verbose = FALSE
)
# These are S3 methods, so the other package's own verb works directly on a
# `tbl_now` -- no explicit converter call needed.
if (requireNamespace("tsibble", quietly = TRUE)) {
suppressWarnings(tsibble::as_tsibble(dengue))
}
#> # A tsibble: 463 x 3 [7D]
#> # Key: report_week [92]
#> onset_week report_week n
#> <date> <date> <int>
#> 1 1990-01-01 1990-01-01 3
#> 2 1990-01-01 1990-01-08 24
#> 3 1990-01-08 1990-01-08 2
#> 4 1990-01-01 1990-01-15 23
#> 5 1990-01-08 1990-01-15 33
#> 6 1990-01-15 1990-01-15 6
#> 7 1990-01-01 1990-01-22 8
#> 8 1990-01-08 1990-01-22 6
#> 9 1990-01-15 1990-01-22 19
#> 10 1990-01-22 1990-01-22 8
#> # ℹ 453 more rows
if (requireNamespace("data.table", quietly = TRUE)) {
head(data.table::as.data.table(dengue))
}
#> onset_week report_week gender .event_num .report_num .delay
#> <Date> <Date> <char> <num> <num> <num>
#> 1: 1990-01-01 1990-01-01 Male 0 0 0
#> 2: 1990-01-01 1990-01-01 Female 0 0 0
#> 3: 1990-01-01 1990-01-01 Female 0 0 0
#> 4: 1990-01-01 1990-01-08 Female 0 1 1
#> 5: 1990-01-01 1990-01-08 Male 0 1 1
#> 6: 1990-01-01 1990-01-15 Female 0 2 2
## Use the `tbl_now_to_*()` function itself when you need its arguments; these
# methods take none beyond `verbose`.