Skip to content

Instantly share code, notes, and snippets.

@dholstius
Last active Oct 22, 2019
Embed
What would you like to do?
show138
library(inventory)
show138 <- function (
DB_year,
category_id,
verbose = TRUE
) {
#' Define the preferred sorting order.
PONSCO_vars <-
c("PM", "TOG", "NOx", "SO2", "CO")
#' Fetch everything for `DB_year`, then drop all but PONSCO.
#' Drop everything but this one particular category.
RY_PONSCO_data <-
point_source_emissions(
DB_year,
verbose = verbose) %>%
filter(
pol_abbr %in% PONSCO_vars) %>%
filter(
cat_id == category_id)
#' Pivot so that PONSCO emissions form columns.
#' Need to drop `pol_id` first, as it's redundant.
wide_format_data <-
RY_PONSCO_data %>%
drop_vars(
pol_id) %>%
spread(
pol_abbr,
ems_qty)
#' Put those columns at the end, in that order.
#' Then sort by facility and source IDs.
rearranged_data <-
wide_format_data %>%
select(
everything(),
-one_of(PONSCO_vars),
PONSCO_vars) %>%
arrange(
fac_id,
src_id,
src_code)
#' Add `tput_qty`, `tput_date`, `tput_basis`, and `tput_CBI`
#' Add `src_name`
show138_data <-
rearranged_data %>%
with_point_source_throughputs(
verbose = verbose) %>%
with_source_name(
verbose = verbose)
return(show138_data)
}
#'
#' Example usage
#'
show138(
DB_year = RY(2007),
category_id = 1595)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment