replace_null_RUV | R Documentation |
In some cases (e.g., bunkers where Last.stage
is "final"),
R, U, U_feed, U_EIOU, or V matrices can be missing, because
imports which appear in the V matrix (or R matrix) are consumed in final demand (Y) matrix,
without any intermediate processing.
When a data frame is pivoted wider by matrices,
the R, U_feed, and U_EIOU columns will contain NULL
entries.
This function fills those NULL
entries with reasonable defaults.
replace_null_RUV(
.sutmats = NULL,
R = IEATools::psut_cols$R,
U_feed = IEATools::psut_cols$U_feed,
U_eiou = IEATools::psut_cols$U_eiou,
U = IEATools::psut_cols$U,
r_eiou = IEATools::psut_cols$r_eiou,
Y = IEATools::psut_cols$Y,
V = IEATools::psut_cols$V,
resources = IEATools::tpes_flows$resources,
.R_temp_name = ".R_temp",
.U_temp_name = ".U_temp",
.U_feed_temp_name = ".U_feed_temp",
.U_eiou_temp_name = ".U_EIOU_temp",
.r_eiou_temp_name = ".r_EIOU_temp",
.V_temp_name = ".V_temp",
R_name = IEATools::psut_cols$R,
U_name = IEATools::psut_cols$U,
U_feed_name = IEATools::psut_cols$U_feed,
U_eiou_name = IEATools::psut_cols$U_eiou,
r_eiou_name = IEATools::psut_cols$r_eiou,
V_name = IEATools::psut_cols$V
)
.sutmats |
A data frame of metadata columns and matrix name columns |
R , U_feed , U_eiou , U , r_eiou , Y , V |
See |
resources |
See |
.R_temp_name , .U_temp_name , .U_feed_temp_name , .U_eiou_temp_name , .r_eiou_temp_name , .V_temp_name |
Names of temporary variables unused internally to the function. |
R_name , U_name , U_feed_name , U_eiou_name , r_eiou_name , V_name |
See |
Reasonable defaults arise from the following thought processes. If all energy is supplied by imports (in the V matrix), there are no resources. Thus, we can replace the missing R matrix with a 0 matrix with a generic "Natural resources" row and the same products as the rows of the Y matrix.
Similarly, missing values for U, U_feed, U_EIOU, or r_EIOU can be replaced by a 0 matrix with row and column names same as a transposed V matrix when it exists. If neither U nor V exist, the R matrix can supply row and column names.
A version of .sutmats
with R, U, U_feed, U_EIOU, or V filled with 0 matrices if they were missing.
# Set up a PSUT data frame with NULL for
# R, U_feed, and U_EIOU in 1971 for GHA.
psut <- load_tidy_iea_df() %>%
specify_all() %>%
prep_psut() %>%
tidyr::pivot_longer(cols = c("R", "U_EIOU", "U_feed", "U", "r_EIOU", "V", "Y", "S_units"),
names_to = "matnames", values_to = "matvals") %>%
dplyr::filter(!(Country == "GHA" & Year == 1971 & matnames == "R")) %>%
dplyr::filter(!(Country == "GHA" & Year == 1971 & matnames == "U_feed")) %>%
dplyr::filter(!(Country == "GHA" & Year == 1971 & matnames == "U_EIOU")) %>%
tidyr::pivot_wider(names_from = "matnames", values_from = "matvals")
# Replace the `NULL` matrices in the first row.
res <- psut %>%
replace_null_RUV()
res$R[[1]]
res$U_feed[[1]]
res$U_EIOU[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.