Processes GTAP data from SL4 and HAR files with options for exporting and preparing plot-ready data.
Usage
auto_gtap_data(
experiment,
project_path = NULL,
input_path = NULL,
output_path = NULL,
sl4_suffix = "",
har_suffix = "-WEL",
mapping_info = "GTAPv7",
process_sl4_vars = NULL,
process_har_vars = NULL,
sl4_mapping_info = NULL,
har_mapping_info = NULL,
sl4_extract_method = "group_data_by_dims",
har_extract_method = "get_data_by_var",
sl4_priority = NULL,
har_priority = NULL,
region_select = NULL,
sector_select = NULL,
subtotal_level = FALSE,
plot_data = FALSE,
output_formats = NULL,
sl4_output_name = "sl4.plot.data",
har_output_name = "har.plot.data",
macro_output_name = "GTAPMacro"
)
Arguments
- experiment
Character vector. Case names to process.
- project_path
Character. Path to the project folder with "in" and "out" subfolders.
- input_path
Character. Path to the input folder. Overrides `project_path/in` if specified.
- output_path
Character. Path to the output folder. Overrides `project_path/out` if specified.
- sl4_suffix
Character. Custom suffix for SL4 files (e.g., "" or "-custom").
- har_suffix
Character. Custom suffix for HAR files (e.g., "-WEL").
- mapping_info
Character. Mapping mode: "GTAPv7" (default), "Yes", "No", or "Mix".
- process_sl4_vars
Data frame, NULL, or FALSE. Variables to extract from SL4 files. - Set to NULL to extract all variables. - Set to FALSE to skip SL4 processing.
- process_har_vars
Data frame, NULL, or FALSE. Variables to extract from HAR files. - Set to NULL to extract all variables. - Set to FALSE to skip HAR processing.
- sl4_mapping_info
Data frame or NULL. Mapping information for SL4 variables (with "Variable", "Description", and "Unit" columns).
- har_mapping_info
Data frame or NULL. Mapping information for HAR variables (with "Variable", "Description", and "Unit" columns).
- sl4_extract_method
Character. SL4 extraction method. Options: "get_data_by_dims", "get_data_by_var", or "group_data_by_dims".
- har_extract_method
Character. HAR extraction method. Options: "get_data_by_dims", "get_data_by_var", or "group_data_by_dims".
- sl4_priority
Optional list. Priority rules for SL4 data grouping.
- har_priority
Optional list. Priority rules for HAR data grouping.
- region_select
Optional character vector. Specifies regions to filter the data.
- sector_select
Optional character vector. Specifies sectors to filter the data.
- subtotal_level
Logical. If TRUE, includes subtotal data. Default is FALSE.
- plot_data
Logical. If TRUE, prepares data for plotting and assigns to variables.
- output_formats
Character vector or list. Exports data in these formats (valid: "csv", "stata", "rds", "txt").
- sl4_output_name
Character. Variable name for SL4 plotting data if generating plot data. Default is "sl4.plot.data".
- har_output_name
Character. Variable name for HAR plotting data if generating plot data. Default is "har.plot.data".
- macro_output_name
Character. Variable name for GTAP macro data if generating plot data. Default is "GTAPMacro".
Details
This function automates the workflow for processing GTAP model outputs, with flexible output options and optional filtering for region- and sector-specific data.
The key parameters `process_sl4_vars` and `process_har_vars` accept three different input types:
Data frame: Contains variable mappings with required "Variable" column. When provided, only specified variables will be extracted.
NULL: Extracts all available variables from the respective file type.
FALSE: Completely skips processing of that file type, allowing the function to focus only on the other file type.
The `mapping_info` parameter controls how descriptions and units are assigned:
GTAPv7: Uses standard GTAPv7 definitions (default).
Yes: Uses only the supplied descriptions and units from `sl4_mapping_info` / `har_mapping_info`.
No: Does not add any descriptions or units.
Mix: Prioritizes supplied descriptions and units, falling back to GTAPv7 for any missing values.
Examples
# 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"),
input_path = input_path, subtotal_level = FALSE,
process_sl4_vars = NULL, process_har_vars = NULL,
mapping_info = "GTAPv7", plot_data = TRUE)
#> All 2 requested experiment files are found with both SL4 and HAR data.
#> Mapping method used: GTAPv7
#> Processing GTAP Macro Data
#> Processing SL4 Data
#> Processing QXS Bilateral Trade Data
#> Processing HAR Data
#>
#> Summary of Processing:
#> GTAP Macro Data processed successfully
#> SL4 Data processed successfully
#> HAR Data processed successfully
#>
#> GTAP data processing completed successfully!