Skip to contents

Coerce to a tibble

Usage

# S3 method for class 'incidence2'
as_tibble(x, ..., .rows, .name_repair, rownames)

Arguments

x

An incidence2 object.

...

Unused, for extensibility.

.rows

The number of rows, useful to create a 0-column tibble or just as an additional check.

.name_repair

Treatment of problematic column names:

  • "minimal": No name repair or checks, beyond basic existence,

  • "unique": Make sure names are unique and not empty,

  • "check_unique": (default value), no name repair, but check they are unique,

  • "universal": Make the names unique and syntactic

  • a function: apply custom name repair (e.g., .name_repair = make.names for names in the style of base R).

  • A purrr-style anonymous function, see rlang::as_function()

This argument is passed on as repair to vctrs::vec_as_names(). See there for more details on these terms and the strategies used to enforce them.

rownames

How to treat existing row names of a data frame or matrix:

  • NULL: remove row names. This is the default.

  • NA: keep row names.

  • A string: the name of a new column. Existing rownames are transferred into this column and the row.names attribute is deleted. No name repair is applied to the new column name, even if x already contains a column of that name. Use as_tibble(rownames_to_column(...)) to safeguard against this case.

Read more in rownames.

Value

A tibble of the original input but with no additional attributes.

Examples

if (requireNamespace("outbreaks", quietly = TRUE)) {
    data(ebola_sim_clean, package = "outbreaks")
    dat <- ebola_sim_clean$linelist
    x <- incidence(dat, "date_of_onset")
    as_tibble(x)
}
#> # A tibble: 367 × 3
#>    date_index count_variable count
#>    <date>     <chr>          <int>
#>  1 2014-04-07 date_of_onset      1
#>  2 2014-04-15 date_of_onset      1
#>  3 2014-04-21 date_of_onset      2
#>  4 2014-04-25 date_of_onset      1
#>  5 2014-04-26 date_of_onset      1
#>  6 2014-04-27 date_of_onset      1
#>  7 2014-05-01 date_of_onset      2
#>  8 2014-05-03 date_of_onset      1
#>  9 2014-05-04 date_of_onset      1
#> 10 2014-05-05 date_of_onset      1
#> # ℹ 357 more rows