Last active
October 22, 2019 21:43
-
-
Save dholstius/16e53e4e078b8bbccb31d546a9c70fe7 to your computer and use it in GitHub Desktop.
show138
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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