compose_date_parts: Assemble a date from separate Year/Quarter/Month/Day columns

View source: R/date_parts.R

compose_date_partsR Documentation

Assemble a date from separate Year/Quarter/Month/Day columns

Description

Real-world tables often split the period across columns (a Year column plus a Quarter or Month column, sometimes plus a Day column) rather than carrying one parseable date. This assembles those into a single Date and reports the finest granularity present, so the caller can aggregate at that level (Year+Quarter -> quarterly, Year+Month -> monthly, and so on) instead of guessing.

Usage

compose_date_parts(
  df,
  year_col,
  quarter_col = NULL,
  month_col = NULL,
  day_col = NULL
)

Arguments

df

A data frame containing the part columns.

year_col

Character scalar, the Year column's name. Required.

quarter_col

Optional character scalar, a Quarter column (accepts 1-4, "Q1"-"Q4", "Quarter 2", etc.). Supply at most one of quarter_col/month_col.

month_col

Optional character scalar, a Month column (accepts 1-12, "Jan", "January", etc.).

day_col

Optional character scalar, a Day-of-month column. Only meaningful alongside month_col.

Value

A list with ds (a Date vector) and granularity (one of "year", "quarter", "month", "day", the finest part supplied).

Examples

df <- data.frame(Year = c(2023, 2023, 2024), Month = c("Jan", "Feb", "Jan"))
compose_date_parts(df, year_col = "Year", month_col = "Month")

forecastsuite documentation built on Oct. 18, 2026, 5:08 p.m.