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)
x | any R object. |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
format | A format that uses a subset of the same placeholders as
Not all placeholders are supported for all |
||||||||||||
... | ignored |
||||||||||||
month_names, month_abb | a |
a character
vector
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")
)
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"