These are Date methods for the arithmetic generics.
Calendrical based arithmetic:
These functions convert to a year-month-day calendar, perform the arithmetic, then convert back to a Date.
Time point based arithmetic:
These functions convert to a time point, perform the arithmetic, then convert back to a Date.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
## S3 method for class 'Date' add_years(x, n, ..., invalid = NULL) ## S3 method for class 'Date' add_quarters(x, n, ..., invalid = NULL) ## S3 method for class 'Date' add_months(x, n, ..., invalid = NULL) ## S3 method for class 'Date' add_weeks(x, n, ...) ## S3 method for class 'Date' add_days(x, n, ...)
A Date vector.
An integer vector to be converted to a duration, or a duration
corresponding to the arithmetic function being used. This corresponds
to the number of duration units to add.
These dots are for future extensions and must be empty.
One of the following invalid date resolution strategies:
Adding a single quarter with
add_quarters() is equivalent to adding
n are recycled against each other.
Only calendrical based arithmetic has the potential to generate invalid dates. Time point based arithmetic, like adding days, will always generate a valid date.
x after performing the arithmetic.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
x <- as.Date("2019-01-01") add_years(x, 1:5) y <- as.Date("2019-01-31") # Adding 1 month to `y` generates an invalid date. Unlike year-month-day # types, R's native Date type cannot handle invalid dates, so you must # resolve them immediately. If you don't you get an error: try(add_months(y, 1:2)) add_months(as_year_month_day(y), 1:2) # Resolve invalid dates by specifying an invalid date resolution strategy # with the `invalid` argument. Using `"previous"` here sets the date to # the previous valid date - i.e. the end of the month. add_months(y, 1:2, invalid = "previous")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.