Clean and pivot useful data frame
stack_final_useful_df.Rd
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
- .sep
A separator between matrix names and
final
oruseful
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
isNULL
).- U_eiou_name, U_feed_name, U_name, r_eiou_name, V_name, Y_name
See
IEATools::psut_cols
. Distinct fromU_feed
,U_eiou
,U
,r_eiou
,V
, andY
(which can be matrices or strings), these variables determine the names of these matrices on output. Default values are taken fromIEATools::psut_cols
. Note that.sep
anduseful
are appended to the strings inU_eiou_name
...Y_name
to form the output names.
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)
#> # A tibble: 8 × 15
#> Country Method EnergyType LastStage Year Y S_units R U
#> <chr> <chr> <chr> <chr> <dbl> <list> <list> <list> <list>
#> 1 GHA PCM E Final 1971 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 2 GHA PCM E Final 2000 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 3 ZAF PCM E Final 1971 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 4 ZAF PCM E Final 2000 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 5 GHA PCM E Useful 1971 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 6 GHA PCM E Useful 2000 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 7 ZAF PCM E Useful 1971 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> 8 ZAF PCM E Useful 2000 <dbl[…]> <dbl[…]> <dbl[…]> <dbl[…]>
#> # ℹ 6 more variables: U_feed <list>, U_EIOU <list>, r_EIOU <list>, V <list>,
#> # Y_fu_details <list>, U_EIOU_fu_details <list>