as_yearweek {grates} | R Documentation |
Coerce to a yearweek object
Description
Generic for conversion to <grates_yearweek>.
Usage
as_yearweek(x, ...)
## Default S3 method:
as_yearweek(x, ...)
## S3 method for class 'Date'
as_yearweek(x, firstday = 1L, ...)
## S3 method for class 'POSIXt'
as_yearweek(x, firstday = 1L, ...)
## S3 method for class 'character'
as_yearweek(
x,
firstday = 1L,
format,
tryFormats = c("%Y-%m-%d", "%Y/%m/%d"),
...
)
## S3 method for class 'factor'
as_yearweek(
x,
firstday = 1L,
format,
tryFormats = c("%Y-%m-%d", "%Y/%m/%d"),
...
)
Arguments
x |
R object. |
... |
Other values passed to as.Date(). |
firstday |
The day the week starts on from 1 (Monday) to 7 (Sunday). |
format |
Passed to as.Date() unless 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
|
tryFormats |
Format strings to try if format is not specified. |
Details
Date, POSIXct, and POSIXlt are converted with the timezone respected.
Character objects are first coerced to date via
as.Date()
unlessformat = "yearweek"
in which case input is assumed to be in the form "YYYY-Wxx" and parsed accordingly.
Value
A <grates_yearweek>
object.
See Also
as.Date()
and new_yearweek()
.
Examples
as_yearweek(Sys.Date())
as_yearweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
as_yearweek("2019-05-03", firstday = 5L)
as_yearweek("2019-W12", format = "yearweek")