stack_final_useful_df: Clean and pivot useful data frame

View source: R/final_to_useful.R

stack_final_useful_dfR Documentation

Clean and pivot useful data frame

Description

After a call to extend_to_useful(), the resulting data frame is not in a great shape. This function gathers (via tidyr::pivot_longer()) and stacks the useful data beneath the final data. A last_stage column is added to discriminate between final and useful versions of matrices.

Usage

stack_final_useful_df(
  .useful_df,
  .sutdata,
  last_stage = IEATools::iea_cols$last_stage,
  useful = IEATools::last_stages$useful,
  .sep = "_",
  C_eiou = IEATools::template_cols$C_eiou,
  C_Y = IEATools::template_cols$C_Y,
  eta_fu = IEATools::template_cols$eta_fu,
  phi_u = IEATools::template_cols$phi_u,
  U_feed_name = IEATools::psut_cols$U_feed,
  U_eiou_name = IEATools::psut_cols$U_eiou,
  U_name = IEATools::psut_cols$U,
  r_eiou_name = IEATools::psut_cols$r_eiou,
  V_name = IEATools::psut_cols$V,
  Y_name = IEATools::psut_cols$Y
)

Arguments

.useful_df

A data frame created by extend_to_useful().

.sutdata

The original input to extend_to_useful().

last_stage

See IEATools::iea_cols$last_stage.

useful

See IEATools::last_stages.

.sep

A separator between matrix names and final or useful indicators. Default is "_".

C_eiou, C_Y, eta_fu, phi_u

See IEATools::template_cols. These should be strings (if .sutdata is a data frame or a list) or individual matrices (if .sutdata is NULL).

U_eiou_name, U_feed_name, U_name, r_eiou_name, V_name, Y_name

See IEATools::psut_cols. Distinct from U_feed,U_eiou, U, r_eiou, V, and Y (which can be matrices or strings), these variables determine the names of these matrices on output. Default values are taken from IEATools::psut_cols. Note that .sep and useful are appended to the strings in U_eiou_name ... Y_name to form the output names.

Value

A nicer form of useful energy and exergy data.

Examples

C_data <- load_fu_allocation_data() %>% 
  form_C_mats()
eta_fu_data <- load_eta_fu_data() %>% 
  form_eta_fu_phi_u_vecs()
m_cols <- eta_fu_data %>% 
  IEATools::meta_cols(return_names = TRUE,
                      years_to_keep = IEATools::iea_cols$year,
                      not_meta = c(IEATools::template_cols$eta_fu,
                                   IEATools::template_cols$phi_u))
psut_mats <- load_tidy_iea_df() %>% 
  specify_all() %>% 
  prep_psut()
extended_to_useful <- psut_mats |> 
  dplyr::full_join(C_data, by = m_cols) %>% 
  dplyr::full_join(eta_fu_data, by = m_cols) |> 
  extend_to_useful()
stack_final_useful_df(extended_to_useful, psut_mats)

MatthewHeun/IEATools documentation built on Feb. 6, 2024, 3:29 p.m.