Processes GTAP data from sl4
and har
files with options for exporting and preparing plot-ready data.
auto_gtap_data(
experiment,
input_path = NULL,
output_path = NULL,
sl4_suffix = "",
har_suffix = "",
process_sl4_vars = NULL,
process_har_vars = NULL,
mapping_info = "GTAPv7",
sl4_mapping_info = NULL,
har_mapping_info = NULL,
sl4_extract_method = "get_data_by_dims",
har_extract_method = "get_data_by_var",
sl4_priority = NULL,
har_priority = NULL,
sl4_convert_unit = NULL,
har_convert_unit = NULL,
decimals = 4,
rename_columns = TRUE,
region_select = NULL,
sector_select = NULL,
subtotal_level = FALSE,
plot_data = TRUE,
output_formats = NULL,
sl4_output_name = "sl4.plot.data",
har_output_name = "har.plot.data",
macro_output_name = "GTAPMacro",
add_scenario_ranking = FALSE,
rank_column = "ScenarioRank"
)
A processed GTAP-formatted dataset with standardized structure and metadata, ready for analysis or visualization.
Character vector. Case names to process.
Character. Path to the input folder.
Character. Path to the output folder.
Character. Custom suffix for SL4 files (e.g., ""
, "-custom"
).
Character. Custom suffix for HAR files (e.g., "-WEL"
).
Character, NULL
, or FALSE
. Variables to extract from SL4 data:
Character vector: Specific variable names.
NULL
: Extract all.
FALSE
: Skip SL4 processing.
Character, NULL
, or FALSE
. Variables to extract from HAR data:
Character vector: Specific variable names.
NULL
: Extract all.
FALSE
: Skip HAR processing.
Character. Metadata mode for variable descriptions and units.
Options: "GTAPv7"
(default), "Yes"
, "No"
, "Mix"
.
See add_mapping_info()
for full details.
Data frame or NULL
. Mapping for SL4 variables. Must include columns "Variable"
, "Description"
, and "Unit"
.
Data frame or NULL
. Mapping for HAR variables, structured as above.
Character. SL4 extraction method: "get_data_by_dims"
, "get_data_by_var"
, or "group_data_by_dims"
.
Character. HAR extraction method. Same options as above.
Optional list. Required only when sl4_extract_method
is "group_data_by_dims"
. Specifies priority rules for SL4 data grouping.
Optional list. Required only when har_extract_method
is "group_data_by_dims"
. Specifies priority rules for HAR data grouping.
Character or NULL
. Optional SL4 unit conversion.
Valid options: "mil2bil"
, "bil2mil"
, "pct2frac"
, "frac2pct"
.
See convert_units
for details.
Character or NULL
. Optional HAR unit conversion. Same options as above.
Integer or NULL
. Number of decimal places to round numeric values. Set to NULL
to disable rounding.
Logical. If TRUE
(default), renames GTAP codes (e.g., "REG"
→ "Region"
, "COMM"
→ "Commodity"
).
Optional character vector. Filters data to selected regions.
Applies only to the "REG"
column, which is fixed and cannot be modified.
Optional character vector. Filters data to selected sectors.
Applies only to the "ACTS"
and "COMM"
columns, which are fixed and cannot be modified.
Logical. If TRUE
, includes subtotal rows. Default is FALSE
.
Logical. If TRUE
, generates plot-ready data and assigns to specified variable names.
Character vector or list. Output formats for export. Valid values: "csv"
, "stata"
, "rds"
, "txt"
.
Character. Variable name to assign SL4 output. Default: "sl4.plot.data"
.
Character. Variable name to assign HAR output. Default: "har.plot.data"
.
Character. Variable name to assign macro output. Default: "GTAPMacro"
.
Logical or "merged"
. Adds a numeric index for each scenario:
TRUE
: Adds a ranking column.
"merged"
: Also prefixes experiment names with the rank.
Character. Name of the ranking column. Default is "ScenarioRank"
.
Pattawee Puangchit
To prepare data for plotting and generating tables within the GTAPViz package, the "Unit"
column must be included in the output.
When using the extraction method "group_data_by_dims"
, the corresponding priority list must be defined via the sl4_priority
or har_priority
argument.
See group_data_by_dims
for more details.
add_mapping_info
, convert_units
,
rename_value
# Input Path:
input_path <- system.file("extdata/in", package = "GTAPViz")
# GTAP Macro Variables from 2 .sl4 Files named (EXP1, EXP2)
# Note: No need to add .sl4 to the experiment name
gtap_data <- auto_gtap_data(experiment = c("EXP1", "EXP2"),
har_suffix = "-WEL",
input_path = input_path, subtotal_level = FALSE,
process_sl4_vars = NULL, process_har_vars = NULL,
mapping_info = "GTAPv7", plot_data = TRUE)
Run the code above in your browser using DataLab