-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
323 changed files
with
13,418 additions
and
12,231 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: IEATools | ||
Type: Package | ||
Title: Tools for Working with International Energy Agency Data | ||
Version: 0.1.75 | ||
Date: 2024-02-03 | ||
Version: 0.1.76 | ||
Date: 2024-12-09 | ||
Authors@R: c(person(given = "Matthew Kuperus", family = "Heun", role = c("aut", "cre"), | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0002-7438-214X")), | ||
|
@@ -15,7 +15,7 @@ License: MIT + file LICENSE | |
Language: en-US | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 7.3.1 | ||
RoxygenNote: 7.3.2 | ||
Roxygen: list(markdown = TRUE) | ||
Depends: R (>= 2.10) | ||
Config/testthat/edition: 3 | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#' Extract a data frame of electricity and heat output information | ||
#' | ||
#' @param .iea_file The IEA data file to read | ||
#' @param electricity_output_prefix The prefix for electricity output rows. | ||
#' Default is `IEATools::elec_heat_output$electricity_output_prefix`. | ||
#' @param heat_output_prefix The prefix for heat output rows. | ||
#' Default is `IEATools::elec_heat_output$heat_output_prefix`. | ||
#' @param country,year,flow,product,e_dot,unit_colname See `IEATools::iea_cols`. | ||
#' @param input_colname,output_colname,output_machine_delimiter See `IEATools::elec_heat_output`. | ||
#' @param machine_colname See `IEATools::template_cols`. | ||
#' @param unit The desired output unit. Default is "TJ". Best not to change this. | ||
#' @param electricity A string that defines electricity output. | ||
#' Default is "Electricity". | ||
#' @param total See `IEATools::memo_aggregation_product_prefixes`. | ||
#' @param memo See `IEATools::memo_aggregation_flow_prefixes`. | ||
#' | ||
#' @return A data frame of electricity and heat output data. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' sample_iea_data_path() |> | ||
#' load_electricity_heat_output() | ||
load_electricity_heat_output <- function(.iea_file = NULL, | ||
electricity_output_prefix = IEATools::elec_heat_output$electricity_output_prefix, | ||
heat_output_prefix = IEATools::elec_heat_output$heat_output_prefix, | ||
country = IEATools::iea_cols$country, | ||
year = IEATools::iea_cols$year, | ||
flow = IEATools::iea_cols$flow, | ||
product = IEATools::iea_cols$product, | ||
e_dot = IEATools::iea_cols$e_dot, | ||
input_colname = IEATools::elec_heat_output$input_product, | ||
output_colname = IEATools::elec_heat_output$output_product, | ||
machine_colname = IEATools::template_cols$machine, | ||
unit_colname = IEATools::iea_cols$unit, | ||
unit = "TJ", | ||
electricity = "Electricity", | ||
output_machine_delimiter = IEATools::elec_heat_output$output_machine_delimiter, | ||
total = IEATools::memo_aggregation_product_prefixes$total, | ||
memo = IEATools::memo_aggregation_flow_prefixes$memo) { | ||
|
||
iea_data <- .iea_file |> | ||
iea_df() |> | ||
rename_iea_df_cols() |> | ||
clean_iea_whitespace() |> | ||
use_iso_countries() | ||
elec_heat_data <- iea_data |> | ||
dplyr::filter((startsWith(.data[[flow]], electricity_output_prefix) | | ||
startsWith(.data[[flow]], heat_output_prefix)), | ||
.data[[product]] != total, | ||
!startsWith(.data[[product]], memo)) |> | ||
tidyr::separate_wider_delim(dplyr::all_of(flow), delim = "-", names = c(output_colname, machine_colname)) |> | ||
dplyr::mutate( | ||
# Capitalize first letter of machine name. | ||
"{machine_colname}" := stringr::str_to_sentence(.data[[machine_colname]]), | ||
# Select only the first word in the output column, either "Electricity" or "Heat" | ||
"{output_colname}" := stringr::word(.data[[output_colname]], 1), | ||
# Fix chp | ||
"{machine_colname}" := stringr::str_replace(.data[[machine_colname]], "chp", "CHP") | ||
) |> | ||
dplyr::rename( | ||
"{input_colname}" := dplyr::all_of(product) | ||
) |> | ||
tidyr::pivot_longer(cols = !dplyr::all_of(c(country, output_colname, machine_colname, input_colname)), | ||
names_to = year, | ||
values_to = e_dot) |> | ||
dplyr::filter(.data[[e_dot]] != 0) |> | ||
dplyr::mutate( | ||
# Convert GWh to TJ for electricity only. | ||
"{e_dot}" := dplyr::case_when( | ||
# Convert for electricity only. | ||
.data[[output_colname]] == electricity ~ .data[[e_dot]] * 3.6, | ||
# Heat is already in TJ. | ||
TRUE ~ .data[[e_dot]] | ||
), | ||
# Set the unit string. | ||
"{unit_colname}" := unit, | ||
# Year should be numeric | ||
"{year}" := as.numeric(.data[[year]]) | ||
) |> | ||
# Update the order of columns. | ||
dplyr::select(dplyr::all_of(c(country, year, input_colname, machine_colname, output_colname, e_dot, unit_colname))) | ||
|
||
return(elec_heat_data) | ||
} |
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
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
Oops, something went wrong.