feat: merge cog_suggestions() from GitHub pull request 1
NEWS.md and NAMESPACE conflicted with the fiscal-period work: both sides added to the development section and the export list. Both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+615
-2
No files matched your search
@@ -0,0 +1,97 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/suggestions.R
|
||||
\name{cog_suggestions}
|
||||
\alias{cog_suggestions}
|
||||
\title{Coverage suggestions for a spending or revenue query}
|
||||
\usage{
|
||||
cog_suggestions(
|
||||
govid,
|
||||
years,
|
||||
category,
|
||||
flow = c("spending", "revenue"),
|
||||
concept = NULL,
|
||||
years_present
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{govid}{Character vector of `canonical_govid` values, or a data frame
|
||||
with a `canonical_govid` column, such as a [cog_find_peers()] or
|
||||
[cog_gov_search()] result. The suggestions cover these governments as one
|
||||
cohort, as they do in a verb call over the same `govid`.}
|
||||
|
||||
\item{years}{Integer vector of requested years.}
|
||||
|
||||
\item{category}{Character vector of category names from
|
||||
`summary_categories.category`, or the reserved `"All Categories"` alone.
|
||||
The verbs build suggestions only when a category is named, so `NULL` is
|
||||
refused here.}
|
||||
|
||||
\item{flow}{`"spending"` for the suggestions [cog_spending()] would attach,
|
||||
or `"revenue"` for [cog_revenue()]'s.}
|
||||
|
||||
\item{concept}{The verb's concept argument: `expenditure_concept` for
|
||||
spending (`"primary"`, `"direct"` or `"total"`) or `revenue_concept` for
|
||||
revenue (`"general"` or `"total"`). `NULL`, the default, uses the verb's
|
||||
own default, `"primary"` or `"general"`. The concept changes the result
|
||||
only when `category = "All Categories"`, where its subtype scope decides
|
||||
which recipes are candidates.}
|
||||
|
||||
\item{years_present}{Integer vector of the years in which your rows for
|
||||
`category` have at least one row. Pass `integer(0)` when there are no
|
||||
rows. Years outside `years` are ignored. With `flow = "spending"` and
|
||||
`concept = "total"`, count only rows whose `spend_subtype` is not
|
||||
`"intergovernmental"`. [cog_spending()] measures gaps on the Direct leg
|
||||
alone, because an intergovernmental row can survive in a year whose
|
||||
Direct rows Census published only as an aggregate.}
|
||||
}
|
||||
\value{
|
||||
A list with one element per suggestion, ordered by `recipe_id`,
|
||||
and identical to `attr(x, "provenance")$suggestions` for the same
|
||||
inputs. Each element is a list with `recipe_id`, `label`,
|
||||
`available_years` (first and last year the recipe covers), `hint`,
|
||||
`trigger` (`"empty_year"` or `"suppressed_component"`),
|
||||
`suppressed_amount` (full US dollars), `suppressed_years`,
|
||||
`suppressed_codes`, and `ig_recipe_id` (the intergovernmental
|
||||
counterpart recipe, or `NULL`). The list is empty when nothing qualifies.
|
||||
}
|
||||
\description{
|
||||
Builds the harmonization-recipe suggestions that [cog_spending()] and
|
||||
[cog_revenue()] attach as `attr(x, "provenance")$suggestions`, without
|
||||
running the verb again. Call a verb once with no `category`, filter its
|
||||
rows yourself, and call this when you need the suggestions for one
|
||||
category.
|
||||
}
|
||||
\details{
|
||||
A suggestion names a recipe (see [cog_recipes()]) that would fill a gap in
|
||||
the result. A recipe qualifies in two ways. Its `trigger` is
|
||||
`"empty_year"` when the result has no rows in a requested year and the
|
||||
recipe's own join finds rows for these governments in that year. Its
|
||||
`trigger` is `"suppressed_component"` when one of the recipe's component
|
||||
codes carries dollars that the verb's own view excludes, because Census
|
||||
published them only as an aggregate or because the code is absent from
|
||||
`summary_categories`.
|
||||
|
||||
Suggestions are built only for the verbs' default `basis = "harmonized"`.
|
||||
On a corpus with `schema_version < 5` that basis is unavailable, the verbs
|
||||
fall back to `"raw"`, and this function returns an empty list, as the
|
||||
verbs do. It also returns an empty list when nothing qualifies.
|
||||
|
||||
The verbs also print the suggestions as a message. This function returns
|
||||
them without printing.
|
||||
}
|
||||
\examples{
|
||||
\dontrun{
|
||||
govids <- c("061037123085", "121011212191")
|
||||
spend <- cog_spending(govids, years = 2011:2012)
|
||||
|
||||
corrections <- spend[spend$category == "Corrections", ]
|
||||
cog_suggestions(
|
||||
govids, years = 2011:2012, category = "Corrections",
|
||||
flow = "spending", years_present = unique(corrections$year)
|
||||
)
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
[cog_spending()], [cog_revenue()], [cog_recipes()],
|
||||
[cog_explain()]
|
||||
}
|
||||
Reference in new issue
Block a user