Coerce and Format to Year-Quarter Strings

format_yq(x, q = NULL, format = "%Y-Q%q")

Arguments

x, q

Two integer (vectors). q is optional and the interpretation of x will depend on whether q is supplied or not:

  • if only x is supplied, x will be passed to as_date_yq() (e.g. x = 20161 means first quarter of 2016)

  • if x and q are supplied, x is interpreted as year and q as quarter.

format

A format that uses a subset of the same placeholders as base::strptime():

%YYear with century (the full year)
%yYear without century (the last two digits of the year)
%mMonth as a decimal numbers (01-12)
%BFull month name
%bAbbreviated month name
%VWeek of the year as decimal number (01-53) as defined in ISO8601

Not all placeholders are supported for all date_xx subclasses. Literal "%" can be escaped with "%%" (as in base::sprintf()).

Value

a character vector

Formatting shorthands

Format shorthand functions in the form of format_y*_[preset]() directly apply formatting presets to anything that can be coerced to a date_xx. This is notably handy as they can be used as a labeling function for ggplot2 axes (see vignette("dint"))

See also

format.date_yq()

Other coerce and format functions: format_ym(), format_yw()

Examples

format_yq(2015, 1)
#> [1] "2015-Q1"
format_yq(20151, format = "short")
#> [1] "short"
format_yq(20151, format = "shorter")
#> [1] "shorter"