Learn R Programming

dint (version 2.1.4)

format_date_xx: Format a date_xx

Description

Format a date_xx

Usage

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

Value

a character vector

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

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

Run this code
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
)

Run the code above in your browser using DataLab