Skip to content

Commit

Permalink
Working on filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHeun committed Jan 2, 2025
1 parent 0e43a32 commit 9201dda
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ which always resolves to the latest release.
- GrossNet
- IndustryAggregation
- ProductAggregation
- ChoppedMat
- ChoppedVar


# PFUPipelineTools 0.1.12 (2024-12-09) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14589472.svg)](https://doi.org/10.5281/zenodo.14589472)
Expand Down
22 changes: 20 additions & 2 deletions R/retrieving.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ pl_collect_from_hash <- function(hashed_table,
#' @param product_aggs A vector of strings identifying the product aggregations desired.
#' `NULL` (the default) means all product aggregations should be returned.
#' Other reasonable values are "Specified", "Despecified", and "Grouped".
#' @param chopped_mats A vector of strings identifying the matrix chops desired.
#' `NULL` (the default) means all chopped matrices should be returned.
#' @param chopped_vars A vector of strings identifying the matrix variables desired.
#' `NULL` (the default) means all chopped variables should be returned.
#' @param collect A boolean that tells whether to download the result.
#' Default is `FALSE`.
#' See details.
Expand Down Expand Up @@ -241,7 +245,7 @@ pl_collect_from_hash <- function(hashed_table,
#' Default is "matval".
#' @param rowtype_colname,coltype_colname The names for row and column type columns in data frames.
#' Defaults are "rowtype" and "coltype", respectively.
#' @param dataset_colname,country_colname,year_colname,method_colname,last_stage_colname,energy_type_colname,gross_net_colname,product_agg_colname,industry_agg_colname Columns that are likely to be in db_table_name
#' @param dataset_colname,country_colname,year_colname,method_colname,last_stage_colname,energy_type_colname,gross_net_colname,product_agg_colname,industry_agg_colname,chopped_mat_colname,chopped_var_colname Columns that are likely to be in db_table_name
#' and may be filtered with `%in%`-style subsetting.
#' @param includes_neu_col The name of a column that tells whether non-energy
#' use (NEU) is included.
Expand All @@ -263,6 +267,8 @@ pl_filter_collect <- function(db_table_name,
includes_neu = TRUE,
industry_aggs = NULL,
product_aggs = NULL,
chopped_mats = NULL,
chopped_vars = NULL,
collect = FALSE,
conn,
schema = schema_from_conn(conn = conn),
Expand All @@ -289,7 +295,9 @@ pl_filter_collect <- function(db_table_name,
dataset_colname = PFUPipelineTools::dataset_info$dataset_colname,
includes_neu_colname = Recca::psut_cols$includes_neu,
product_agg_colname = PFUPipelineTools::aggregation_df_cols$product_aggregation,
industry_agg_colname = PFUPipelineTools::aggregation_df_cols$industry_aggregation) {
industry_agg_colname = PFUPipelineTools::aggregation_df_cols$industry_aggregation,
chopped_mat_colname = PFUPipelineTools::aggregation_df_cols$chopped_mat,
chopped_var_colname = PFUPipelineTools::aggregation_df_cols$chopped_var) {

matrix_class <- match.arg(matrix_class)

Expand Down Expand Up @@ -355,6 +363,16 @@ pl_filter_collect <- function(db_table_name,
out <- out |>
dplyr::filter(.data[[product_agg_colname]] %in% prodaggs)
}
if (!is.null(chopped_mats) & chopped_mat_colname %in% cnames) {
chopped_mats <- unlist(chopped_mats)
out <- out |>
dplyr::filter(.data[[chopped_mat_colname]] %in% chopped_mats)
}
if (!is.null(chopped_vars) & chopped_var_colname %in% cnames) {
chopped_vars <- unlist(chopped_vars)
out <- out |>
dplyr::filter(.data[[chopped_var_colname]] %in% chopped_vars)
}

if (collect) {
# Collect (execute the SQL), if desired.
Expand Down
14 changes: 12 additions & 2 deletions man/pl_filter_collect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9201dda

Please sign in to comment.