check_data: Check and prepare tsibble data

View source: R/prepare_data.R

check_dataR Documentation

Check and prepare tsibble data

Description

Check that the input data is a valid regular and ordered tsibble, fill implicit gaps if requested, and convert wide data to long format.

Usage

check_data(data, fill_missing = TRUE)

Arguments

data

A tsibble in long or wide format.

fill_missing

Logical value. If TRUE, implicit missing values are turned into explicit missing values with fill_gaps().

Details

check_data() is a data preparation helper for time series workflows. It performs three tasks:

  • checks that data is a tsibble;

  • checks that the time index is regular and ordered by key and index;

  • optionally turns implicit missing values into explicit missing values using fill_gaps().

If the input data has no key variables, it is treated as wide data and is converted to long format. The resulting output contains the original index column, a variable column containing the former column names, and a value column containing the corresponding observations.

Existing explicit missing values are not changed.

Value

A tsibble prepared for downstream use. Wide data is returned in long format with one measurement variable named value.

See Also

Other data preparation: interpolate_missing(), smooth_outlier()

Examples

library(dplyr)
library(tsibble)

data <- M4_monthly_data |>
  filter(series %in% c("M23100", "M14395")) |>
  as_tsibble(
    index = index,
    key = series
  )

check_data(data)

wide_data <- data |>
  as_tibble() |>
  select(index, series, value) |>
  tidyr::pivot_wider(
    names_from = series,
    values_from = value
  ) |>
  as_tsibble(index = index)

check_data(wide_data)

tscv documentation built on May 13, 2026, 9:07 a.m.