assemble_fu_allocation_tables: Assemble completed final-to-useful allocation tables

View source: R/table_functions.R

assemble_fu_allocation_tablesR Documentation

Assemble completed final-to-useful allocation tables

Description

This function is used in a drake workflow to assemble completed final-to-useful allocation tables given a set of incomplete allocation tables.

Usage

assemble_fu_allocation_tables(
  incomplete_allocation_tables,
  exemplar_lists,
  specified_iea_data,
  countries,
  max_year = NULL,
  country = IEATools::iea_cols$country,
  year = IEATools::iea_cols$year,
  exemplars = PFUWorkflow::exemplar_names$exemplars,
  exemplar_tables = PFUWorkflow::exemplar_names$exemplar_tables,
  iea_data = PFUWorkflow::exemplar_names$iea_data,
  incomplete_alloc_tables = PFUWorkflow::exemplar_names$incomplete_alloc_table,
  complete_alloc_tables = PFUWorkflow::exemplar_names$complete_alloc_table
)

Arguments

incomplete_allocation_tables

A data frame containing (potentially) incomplete final-to-useful allocation tables. This data frame may be tidy or wide by years.

exemplar_lists

A data frame containing country and year columns along with a column of ordered vectors of strings telling which countries should be considered exemplars for the country and year of this row.

specified_iea_data

A data frame containing specified IEA data.

countries

A vector of countries for which completed final-to-useful allocation tables are to be assembled.

max_year

The latest year for which analysis is desired. Default is NULL, meaning analyze all years.

country, year

See IEATools::iea_cols.

exemplars, exemplar_tables, iea_data, incomplete_alloc_tables, complete_alloc_tables

See PFUWorkflow::exemplar_names.

Details

Note that this function can accept tidy or wide by year data frames. The return value is a tidy data frame. Information from exemplar countries is used to complete incomplete final-to-useful efficiency tables. See examples for how to construct exemplar_lists.

Value

A tidy data frame containing completed final-to-useful allocation tables.

Examples

# Load final-to-useful allocation tables, but eliminate one category of consumption,
# Residential consumption of Primary solid biofuels,
# which will be filled by the exemplar for GHA, ZAF.
incomplete_fu_allocation_tables <- IEATools::load_fu_allocation_data() %>%
  dplyr::filter(! (Country == "GHA" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential"))
# Show that those rows are gone.
incomplete_fu_allocation_tables %>%
  dplyr::filter(Country == "GHA" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential")
# But the missing rows of GHA are present in allocation data for ZAF.
incomplete_fu_allocation_tables %>%
  dplyr::filter(Country == "ZAF" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential")
# Set up exemplar list
el <- tibble::tribble(
  ~Country, ~Year, ~Exemplars,
  "GHA", 1971, c("ZAF"),
  "GHA", 2000, c("ZAF"))
el
# Load IEA data
iea_data <- IEATools::load_tidy_iea_df() %>%
  IEATools::specify_all()
# Assemble complete allocation tables
completed <- assemble_fu_allocation_tables(incomplete_allocation_tables =
                                             incomplete_fu_allocation_tables,
                                           exemplar_lists = el,
                                           specified_iea_data = iea_data,
                                           countries = "GHA")
# Missing data for GHA has been picked up from ZAF.
completed %>%
  dplyr::filter(Country == "GHA" & Ef.product == "Primary solid biofuels" &
    Destination == "Residential")

MatthewHeun/SEAPSUTWorkflow documentation built on April 22, 2022, 2:21 p.m.