Format a date_xx

# S3 method for date_y
format(x, format = "%Y", ...)

# S3 method for date_yq
format(
  x,
  format = "%Y-Q%q",
  month_names = format(ISOdate(2000, 1:12, 1), "%B"),
  month_abb = format(ISOdate(2000, 1:12, 1), "%b"),
  ...
)

# S3 method for date_ym
format(
  x,
  format = "%Y-M%m",
  month_names = format(ISOdate(2000, 1:12, 1), "%B"),
  month_abb = format(ISOdate(2000, 1:12, 1), "%b"),
  ...
)

# S3 method for date_yw
format(x, format = "%Y-W%V", ...)

format_yq_iso(x)

format_yq_short(x)

format_yq_shorter(x)

format_ym_iso(x)

format_ym_short(x)

format_ym_shorter(x)

format_yw_iso(x)

format_yw_short(x)

format_yw_shorter(x)

Arguments

x

any R object.

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()).

...

ignored

month_names, month_abb

a character vector of length 12: Names and abbreviations for months that will be used for the placeholders "%b" and "%B". Defaults to the values for the current locale for compatibility with base::strptime().

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"))

Examples

x <- date_ym(2018, c(1L, 10L, 3L, 6L, 4L, 5L, 7L, 12L, 2L, 9L, 8L, 11L)) fm <- "%Y-M%m: %B,%b" format( x, format = fm, month_names = month.name, # built-in R constant for English names month_abb = month.abb )
#> [1] "2018-M01: January,Jan" "2018-M10: October,Oct" #> [3] "2018-M03: March,Mar" "2018-M06: June,Jun" #> [5] "2018-M04: April,Apr" "2018-M05: May,May" #> [7] "2018-M07: July,Jul" "2018-M12: December,Dec" #> [9] "2018-M02: February,Feb" "2018-M09: September,Sep" #> [11] "2018-M08: August,Aug" "2018-M11: November,Nov"