Learn R Programming

incidence2 (version 2.6.1)

as: Coerce to and from an incidence object

Description

Generic for coercion to an <incidence2> object.

Usage

as_incidence(x, ...)

# S3 method for default as_incidence(x, ...)

# S3 method for incidence2 as_incidence(x, ...)

# S3 method for incidence2 as.data.frame(x, row.names, optional, ...)

# S3 method for incidence2 as.data.table(x, keep.rownames, ...)

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

Value

An object of the desired type with additional attributes dropped.

Arguments

x

An R object.

...

Additional arguments to be passed to or from other methods.

row.names

Not used.

optional

Not used.

keep.rownames

Not used.

.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.

Examples

Run this code
.old <- data.table::setDTthreads(2)
if (requireNamespace("outbreaks", quietly = TRUE)) {
    data(ebola_sim_clean, package = "outbreaks")
    dat <- ebola_sim_clean$linelist
    x <- incidence(dat, "date_of_onset")
    as.data.frame(dat)
    as.data.table(x)
    as_tibble(x)
}
data.table::setDTthreads(.old)

Run the code above in your browser using DataLab