Reads matrices from named regions in an Excel file
into matsindf
format.
The named regions are assumed to be global
to the workbook.
The format for the region names is assumed to be
<<matrix symbol>><<sep>><<worksheet name>>
,
as written by write_ecc_to_excel()
.
For example, "R__4" for the R matrix on the sheet named "4".
Usage
read_ecc_from_excel(
path,
worksheets = NULL,
add_rc_types = TRUE,
worksheet_names_colname = "WorksheetNames",
R = Recca::psut_cols$R,
U = Recca::psut_cols$U,
V = Recca::psut_cols$V,
Y = Recca::psut_cols$Y,
r_eiou = Recca::psut_cols$r_eiou,
U_eiou = Recca::psut_cols$U_eiou,
U_feed = Recca::psut_cols$U_feed,
S_units = Recca::psut_cols$S_units,
industry_type = Recca::row_col_types$industry_type,
product_type = Recca::row_col_types$product_type,
unit_type = Recca::row_col_types$unit_type,
sep = "__"
)
Arguments
- path
The path to the Excel file.
- worksheets
Names of worksheets from which matrices are to be read. Default is
NULL
, meaning that all worksheets are read.- add_rc_types
A boolean that tells whether to add row and column types to the outgoing matrices. When
TRUE
, matrix names are determined byadd_row_col_types()
. Default isTRUE
.- worksheet_names_colname
The name of a column in the outgoing data frame that contains the names of worksheets on which the matrices were found. Default is "WorksheetNames".
- R, U, V, Y, r_eiou, U_eiou, U_feed, S_units
String names for regions in the file at
path
containing matrices. SeeRecca::psut_cols
for defaults.- industry_type, product_type, unit_type
String names of row and column types optionally applied to matrices read from the file at
path
. Defaults are taken fromRecca::row_col_types
.- sep
The separator between matrix name and worksheet name for named regions. Default is "__".
Value
A data frame in matsindf
format containing
the matrices from named regions in
the file at path
.
Details
Named regions are assumed to include
the rectangle of numerical values,
row names (to the left of the rectangle of numbers), and
column names (above the rectangle of numbers),
the same format
as written by write_ecc_to_excel()
.
This function is an inverse of write_ecc_to_excel()
.
Examples
if (FALSE) { # \dontrun{
ecc <- UKEnergy2000mats |>
tidyr::spread(key = "matrix.name", value = "matrix") |>
dplyr::mutate(
WorksheetNames = paste0(EnergyType, "_", LastStage)
)
ecc_temp_path <- tempfile(pattern = "write_excel_ecc_test_file",
fileext = ".xlsx")
write_ecc_to_excel(ecc,
path = ecc_temp_path,
worksheet_names = "WorksheetNames",
overwrite = TRUE)
# Now read the regions
ecc_temp_path |>
read_ecc_from_excel()
if (file.exists(ecc_temp_path)) {
file.remove(ecc_temp_path)
}
} # }