The roxygen comments use markdown (**bold**, `code`, [cog_x()] links, bullet lists) but DESCRIPTION had no `Roxygen: list(markdown = TRUE)`, so the generated .Rd files carried that syntax literally. It also meant a bare `%` started an Rd comment and silently cut the rest of its line from seven places in the rendered pages, including "7% of the no-filter floor", "-32.7% to +251.0% across 24 years" and the `filter(role %in% ...)` line of cog_peer_compare()'s example. Adds the setting and regenerates man/ with roxygen2 7.3.3 (matching RoxygenNote). The only source change is escaping one literal "[min year, max year]" in an @noRd block in R/balance_caveats.R, which markdown mode otherwise reads as a link. No wording or code changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qbe6u2h83wgZdTgJgE4Xh5
131 lines
6.5 KiB
R
131 lines
6.5 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/balances.R
|
|
\name{cog_balances}
|
|
\alias{cog_balances}
|
|
\title{Cash and security holdings for one or more governments}
|
|
\usage{
|
|
cog_balances(
|
|
govid = NULL,
|
|
years,
|
|
category = NULL,
|
|
per_capita = FALSE,
|
|
adjust_to_year = NULL,
|
|
basis = c("harmonized", "raw"),
|
|
recipe = NULL,
|
|
state = NULL,
|
|
type = NULL,
|
|
limit = NULL,
|
|
offset = NULL,
|
|
fiscal_period = FALSE
|
|
)
|
|
}
|
|
\arguments{
|
|
\item{govid}{Canonical govid(s): a character vector, or a data frame with a
|
|
\code{canonical_govid} column (e.g. from \code{\link[=cog_gov_search]{cog_gov_search()}}). \code{NULL} to name
|
|
the cohort by \code{state}/\code{type} instead.}
|
|
|
|
\item{years}{Integer vector of fiscal years.}
|
|
|
|
\item{category}{Optional character vector of categories to keep. One of
|
|
\code{"Fund Balances"}, \code{"Insurance Trust Balances"},
|
|
\code{"Retirement System Holdings"}. There is deliberately no \code{subtype}
|
|
argument: for holdings, \code{category} is a strict coarsening of
|
|
\code{balance_subtype} (unlike the money verbs, where the two axes cross), so
|
|
every combination would be either redundant or empty.
|
|
\code{category = "Fund Balances"} is exactly the \code{general} family
|
|
(\code{W01}/\code{W31}/\code{W61}). \code{balance_subtype} is returned, so a finer split is
|
|
one \code{dplyr::filter()} away. The reserved pseudo-category
|
|
\code{"All Categories"} (see \code{\link[=cog_spending]{cog_spending()}}) is \strong{not} supported here and
|
|
errors with class \code{uscogdata_all_categories_unsupported}: it sums a
|
|
concept's subtype scope, and holdings are a stock with no concept
|
|
vocabulary to sum across. Omit \code{category} to get every category broken
|
|
out instead.}
|
|
|
|
\item{per_capita}{Divide holdings by population. Note this is a \strong{stock per
|
|
resident} (reserves per person), which is \emph{not} comparable to
|
|
\code{\link[=cog_spending]{cog_spending()}}'s per-capita figures -- those are a flow per person.}
|
|
|
|
\item{adjust_to_year}{Deflate to this year's dollars (CPI-U).}
|
|
|
|
\item{basis}{Accepted for uniformity with the money verbs, but currently a
|
|
\strong{no-op}: \code{harmonization_map} carries no balance-code rows, so harmonized
|
|
and raw space are identical for holdings. Reported in
|
|
\code{provenance$basis_note}.}
|
|
|
|
\item{recipe}{Optional harmonization recipe id (see \code{\link[=cog_recipes]{cog_recipes()}}).
|
|
\code{"cash_securities_z77_wide"} and \code{"cash_securities_z78_wide"} bridge the
|
|
wide era to the modern one.}
|
|
|
|
\item{state, type}{Name the cohort by predicate instead of by id: \code{state} is
|
|
a 2-letter USPS abbreviation (or a FIPS code) and \code{type} is one of
|
|
\code{"state"}, \code{"county"}, \code{"city"}, \code{"township"} (or the integer \code{0:3}) --
|
|
the same vocabulary, and the same internal coercion, as
|
|
\code{\link[=cog_gov_search]{cog_gov_search()}}. Both default to \code{NULL}.
|
|
|
|
The cohort is then expressed as a subquery against \code{canonical_fips_xwalk}
|
|
inside each statement rather than round-tripped through R as a literal id
|
|
list. For a fleet-scale cohort that is the difference between a
|
|
301,591-character \code{IN} list re-parsed in 5--8 statements per call and a
|
|
constant-size predicate: measured at \strong{94 ms versus 449 ms} for the same
|
|
FY2022 aggregate over the 20,106-government \code{type = "city"} cohort, within
|
|
7\% of the no-filter floor.
|
|
|
|
Supplying \code{govid} \strong{and} \code{state}/\code{type} INTERSECTS them -- the
|
|
governments in \code{govid} that also match the predicate -- rather than one
|
|
silently taking precedence. Naming no cohort at all (\code{govid}, \code{state} and
|
|
\code{type} all \code{NULL}) aborts with class \code{uscogdata_no_cohort}.
|
|
|
|
When the cohort is named by predicate, \code{provenance$scope$govids_found}
|
|
and \code{govids_missing} are empty -- there is no id list to report against --
|
|
and \code{provenance$scope$cohort} carries \code{state}, \code{type} and
|
|
\code{n_governments} instead. A \code{govid}-named cohort reports exactly as before.}
|
|
|
|
\item{limit}{Maximum number of result rows to return, pushed into the SQL
|
|
rather than applied after materializing every row. \code{NULL} (default)
|
|
returns everything. Cannot be combined with \code{recipe} -- see \code{offset} and
|
|
\code{total_rows}.}
|
|
|
|
\item{offset}{Rows to skip before \code{limit} starts counting (0-based).
|
|
Ignored if \code{limit} is \code{NULL}; defaults to \code{0L} when \code{limit} is set.}
|
|
|
|
\item{fiscal_period}{If \code{TRUE}, add \code{fiscal_year_end}, \code{period_start} and
|
|
\code{period_end} to every row, as \code{\link[=cog_spending]{cog_spending()}} does. Holdings are a stock
|
|
measured at the end of the fiscal year, so \code{period_end} is the date the
|
|
balance describes and \code{period_start} is the start of that fiscal year.
|
|
Defaults to \code{FALSE}, which leaves the result unchanged.}
|
|
}
|
|
\value{
|
|
Tibble with columns \code{year}, \code{canonical_govid}, \code{gov_name},
|
|
\code{balance_subtype}, \code{category}, \code{amt_nominal}, \code{codes_included},
|
|
\code{aggregate_fallback}, plus optional \code{amt_per_capita_nominal} and
|
|
\code{pop_source} (when \code{per_capita = TRUE}), optional \code{amt_real} (when
|
|
\code{adjust_to_year} is set), and optional \code{amt_per_capita_real} (only when
|
|
\strong{both} \code{per_capita = TRUE} and \code{adjust_to_year} are set -- there is no
|
|
nominal per-capita column to deflate otherwise), and \code{fiscal_year_end},
|
|
\code{period_start} and \code{period_end} when \code{fiscal_period = TRUE}. Amounts are
|
|
full US dollars.
|
|
|
|
Carries a \code{provenance} attribute matching
|
|
\code{inst/schemas/provenance-v1.json}, whose \code{balance_caveats} block reports
|
|
\code{not_gaap}, \code{not_gaap_note}, \code{coverage_window} (measured year extents for
|
|
every balance subtype in the mounted corpus, not only the observed ones)
|
|
and \code{truncated} (the observed subtypes whose coverage falls short of the
|
|
requested years). \code{expenditure_concept}/\code{revenue_concept} are \code{NA} --
|
|
holdings are a stock, not a flow, so neither concept vocabulary applies.
|
|
|
|
When \code{limit} is set, also carries a \code{total_rows} attribute: the full
|
|
unpaginated row count, computed by the same query (\verb{COUNT(*) OVER()})
|
|
rather than a second scan.
|
|
}
|
|
\description{
|
|
Returns Census cash-and-security holdings (\code{category_type = "balance"}):
|
|
fund balances, retirement system holdings and insurance trust balances.
|
|
}
|
|
\section{Holdings are not GAAP fund balance}{
|
|
|
|
Census holdings are \strong{gross} -- no liabilities are netted -- so a reserve
|
|
ratio built from them overstates what is actually available. They are not
|
|
comparable to a GAAP fund balance from an ACFR.
|
|
}
|
|
|