paste0("https://apps.bea.gov/api/data/?&",
"UserID=", bea_key, "&",
"method=GetParameterValues&",
"datasetname=NIPA&",
"ParameterName=TableName&") |>
fromJSON() |>
pluck("BEAAPI", "Results", "ParamValue") |>
select(TableName, Description) |>
mutate(N = 1:n()) %>%
filter(TableName %in% (list.files(pattern = "\\.qmd$") %>% gsub(".qmd$", "", .))) |>
# Data-file date: each T<name>.qmd page reads T<name>_{A,Q,M}.parquet
# (annual / quarterly / monthly, written by _download_one_NIPA.R) and/or a
# plain T<name>.parquet. The old code looked at a non-existent
# T<name>.RData, so every Download cell rendered as "NA". Take the newest
# of whichever of those files exist; blank if the table has no data file.
mutate(Download = suppressWarnings(do.call(pmax, c(
lapply(c(".parquet", "_A.parquet", "_Q.parquet", "_M.parquet"), function(sfx)
as.Date(file.info(paste0("~/iCloud/website/data/bea/", TableName, sfx))$mtime)),
na.rm = TRUE)))) |>
mutate(Download = ifelse(is.na(Download), "",
paste0('<a target=_blank href=https://apps.bea.gov/iTable/iTable.cfm?reqid=19&step=3&isuri=1&nipa_table_list=', N, '&categories=survey>', Download, '</a>'))) |>
mutate(Compile = as.Date(file.info(paste0("~/iCloud/website/data/bea/", TableName, ".html"))$mtime)) |>
mutate(Compile = ifelse(is.na(Compile), "",
paste0('<a target=_blank href=', TableName, '.html>', Compile, '</a>'))) |>
select(-N) %>%
{if (is_html_output()) datatable(., filter = 'top', rownames = F, escape = F) else .}