Skip to contents

Generic for conversion to <grates_epiweek>

Usage

as_epiweek(x, ...)

# Default S3 method
as_epiweek(x, ...)

# S3 method for class 'Date'
as_epiweek(x, ...)

# S3 method for class 'POSIXt'
as_epiweek(x, ...)

# S3 method for class 'character'
as_epiweek(x, format, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), ...)

# S3 method for class 'factor'
as_epiweek(x, format, tryFormats = c("%Y-%m-%d", "%Y/%m/%d"), ...)

Arguments

x

R object.

...

Other values passed to as.Date().

format

[character]

Passed to as.Date() unless format = "yearweek" in which case input is assumed to be in the form "YYYY-Wxx".

If not specified, it will try tryFormats one by one on the first non-NA element, and give an error if none works. Otherwise, the processing is via strptime() whose help page describes available conversion specifications.

tryFormats

[character]

Format strings to try if format is not specified.

Value

A <grates_epiweek> object.

Details

  • Date, POSIXct, and POSIXlt are converted with the timezone respected.

  • Character objects are first coerced to date via as.Date() unless format = "yearweek" in which case input is assumed to be in the form "YYYY-Wxx" and parsed accordingly.

See also

Examples

as_epiweek(Sys.Date())
#> <grates_epiweek[1]>
#> [1] "2024-W47"
as_epiweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
#> <grates_epiweek[1]>
#> [1] "2019-W10"
as_epiweek("2019-05-03")
#> <grates_epiweek[1]>
#> [1] "2019-W18"
as_epiweek("2019-W12", format = "yearweek")
#> <grates_epiweek[1]>
#> [1] "2019-W12"