Skip to contents

Generic for conversion to <grates_isoweek>

Usage

as_isoweek(x, ...)

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

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

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

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

# S3 method for class 'factor'
as_isoweek(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_isoweek> 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_isoweek(Sys.Date())
#> <grates_isoweek[1]>
#> [1] "2024-W47"
as_isoweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
#> <grates_isoweek[1]>
#> [1] "2019-W10"
as_isoweek("2019-05-03")
#> <grates_isoweek[1]>
#> [1] "2019-W18"
as_isoweek("2019-W12", format = "yearweek")
#> <grates_isoweek[1]>
#> [1] "2019-W12"