year_class: Year class

year_classR Documentation

Year class

Description

Years are represented by a ⁠<grates_year>⁠ object.

Usage

year(x = integer())

as_year(x, ...)

## Default S3 method:
as_year(x, ...)

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

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

## S3 method for class 'character'
as_year(x, ...)

## S3 method for class 'factor'
as_year(x, ...)

is_year(object)

Arguments

x, object

R objects.

...

Only used For character input where additional arguments are passed through to as.Date().

Details

year() takes as input a vector representing, unsurprisingly, the years. double vectors are coerced via as.integer(floor(x)).

as_yearquarter() is a generic for coercing input in to ⁠<grates_year>⁠.

  • Character input is first parsed using as.Date().

  • POSIXct and POSIXlt are converted with their timezone respected.

Value

A ⁠<grates_year>⁠ object.

Examples


# date coercion
as_year(Sys.Date())

# POSIXt coercion
as_year(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))

# Character coercion
as_year("2019-05-03")

# direct construction
year(2011:2020)


grates documentation built on April 3, 2025, 10:49 p.m.