reviser stores vintages in two S3 classes that sit on top of a tibble and
record what the columns mean. Both are produced by the package's own
constructors; you normally do not create them by hand.
tbl_pubdateVintages identified by publication date, as returned by
vintages_wide(),vintages_long()andget_revisions().tbl_releaseVintages identified by release number, as returned by
get_first_release(),get_nth_release(),get_latest_release(),get_fixed_release()andget_releases_by_date().
validate_vintages() checks that an object conforms to the contract below.
This is useful after manipulating a vintages object with external tools,
which can leave the class attribute in place while breaking the assumptions
the methods rely on.
Data contract
Every object of either class has a time column of dates and may carry an
optional id column identifying the series. Beyond that, each class has
two permitted layouts:
- long
A key column (
pub_datefortbl_pubdate,releasefortbl_release) together with avaluecolumn.- wide
One column per vintage. For
tbl_pubdatethe column names are publication dates in%Y-%m-%dform; fortbl_releasethey are release labels matchingreleaseorfinal.
Columns must be atomic and scalar-valued; list columns are not permitted.
The two classes are not mutually exclusive: a long release table carries
both a release and a pub_date column and holds both classes.
Methods
Both classes support print(), summary() and plot(). The plot methods
dispatch to plot_vintages(), which remains available for direct use when
you want to pass its arguments explicitly. print() uses a pillar header
that reports the layout, the number of periods and the number of vintages.
Examples
df <- dplyr::filter(reviser::gdp, id == "US")
releases <- get_nth_release(df, n = 0:3)
validate_vintages(releases)
# A malformed time column is rejected
broken <- releases
broken$time <- as.character(broken$time)
broken$time[1] <- "not a date"
try(validate_vintages(broken))
#> Error in validate_vintages(broken) :
#> The 'time' column must contain dates in '%Y-%m-%d' format.
# So is a class attribute that contradicts the columns
mislabelled <- vintages_wide(df)$US
class(mislabelled) <- c("tbl_release", class(mislabelled))
try(validate_vintages(mislabelled))
#> Error in validate_vintages(mislabelled) :
#> Object is classed as 'tbl_release', so it must have a 'release' column (long format) or release labels as column names (wide format).
