year-quarter-day-setters {clock} | R Documentation |
Setters: year-quarter-day
Description
These are year-quarter-day methods for the setter generics.
-
set_year()
sets the fiscal year. -
set_quarter()
sets the fiscal quarter of the year. Valid values are in the range of[1, 4]
. -
set_day()
sets the day of the fiscal quarter. Valid values are in the range of[1, 92]
. There are sub-daily setters for setting more precise components.
Usage
## S3 method for class 'clock_year_quarter_day'
set_year(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_quarter(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_day(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_hour(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_minute(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_second(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_millisecond(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_microsecond(x, value, ...)
## S3 method for class 'clock_year_quarter_day'
set_nanosecond(x, value, ...)
Arguments
x |
A year-quarter-day vector. |
value |
The value to set the component to. For |
... |
These dots are for future extensions and must be empty. |
Value
x
with the component set.
Examples
library(magrittr)
# Quarter precision vector
x <- year_quarter_day(2019, 1:4)
x
# Promote to day precision by setting the day
x <- set_day(x, 1)
x
# Or set to the last day of the quarter
x <- set_day(x, "last")
x
# What year-month-day is this?
as_year_month_day(x)
# Set to an invalid day of the quarter
# (not all quarters have 92 days)
invalid <- set_day(x, 92)
invalid
# Here are the invalid ones
invalid[invalid_detect(invalid)]
# Resolve the invalid dates by choosing the previous/next valid moment
invalid_resolve(invalid, invalid = "previous")
invalid_resolve(invalid, invalid = "next")
# Or resolve by "overflowing" by the number of days that you have
# gone past the last valid day
invalid_resolve(invalid, invalid = "overflow")
# This is similar to
days <- get_day(invalid) - 1L
invalid %>%
set_day(1) %>%
as_naive_time() %>%
add_days(days) %>%
as_year_quarter_day()
[Package clock version 0.7.1 Index]