This document provides a list of frequently asked questions (FAQs) and their corresponding solutions related to the GTAPViz package. Users can identify relevant issues and run the suggested solutions by copying and pasting the code into their R script and run!

Package Help

Many helpful functions—such as how to rename values or columns—are not covered in this brief README.
For complete documentation, please refer to the links provided in the badges below.

GPT-GTAPViz

GTAPViz-Vignettes

GTAPViz-Parameters

GTAPViz-Issue Reports

Package Versions

Install GTAPViz for the first time

# Install the GTAPViz package (note: case-sensitive)
install.packages("GTAPViz")

# Check the installed version of GTAPViz
library(GTAPViz)
packageVersion("GTAPViz")

Undefined Functions

Common Issue:

  • When running the code, an error indicates unused arguments or parameters, or an old version of the package is detected.

Solution 1

Show/Hide

Try force-reinstalling the updated version of GTAPViz.

  1. Restart your R session (close and reopen R), or go to Session > Restart R in RStudio.

  2. Reinstall the package using the following code:

# Remove the package (if installed)
if ("GTAPViz" %in% installed.packages()) {
  remove.packages("GTAPViz")
}

# Clear from memory (if loaded)
if ("GTAPViz" %in% loadedNamespaces()) {
  detach("package:GTAPViz", unload = TRUE, character.only = TRUE)
}

# Reinstall the latest version from CRAN
install.packages("GTAPViz")

# Check the version of GTAPViz
library(GTAPViz)
packageVersion("GTAPViz")

Solution 2

Show/Hide

If Solution 1 does not work, the CRAN version of GTAPViz may be outdated.
Try removing the currently installed CRAN version and reinstalling the latest development version from GitHub:

# Remove the package (if installed)
if ("GTAPViz" %in% installed.packages()) {
  remove.packages("GTAPViz")
}

# Clear from memory (if loaded)
if ("GTAPViz" %in% loadedNamespaces()) {
  detach("package:GTAPViz", unload = TRUE, character.only = TRUE)
}

# Install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
  install.packages("devtools")
}

# Force reinstallation of the latest version from GitHub
devtools::install_github("Bodysbobb/GTAPViz", force = TRUE)
require(GTAPViz)

# Check the version of GTAPViz
packageVersion("GTAPViz")

Get Empty Outputs

Common Issue:

  • Returns empty outputs when running the code.

Solution 1

Show/Hide
  • Check the “OutputMapping.xlsx” file in the /map folder. Make sure that all three sheets are well defined, and verify that the specified “Variables”, “Regions”, and “Sectors” exist in the input files.

  • Check the project directory to ensure it includes the /in folder, and confirm that all input file names listed in the experiment file are correctly defined and match the actual input filenames.

  • Check the variables (and other names) in the input files (.sl4 and .har). Ensure that they exactly match the names defined in the “OutputMapping.xlsx” file (note: names are case-sensitive).

Solution 2

Show/Hide

If you have tried all steps in Solution 1 but are still getting empty outputs, try running the following code to clear all R objects in the environment and attempt to re-extract all variables (this may take some time):

# Define 
project.folder <- "D:/One Drive/OneDrive - purdue.edu/GTAPViz Data/users"
experiment <- c("IncreaseTar10", "IncreaseTar50", "ReduceTar20")


# DO NOT CHANGE BELOW THIS LINE

## Checking Folders
input.folder <- paste0(project.folder, "/in")
map.folder <- paste0(project.folder, "/map")

# Function to check and report folder existence
check_folder <- function(folder.name, folder.path) {
  if (!dir.exists(folder.path)) {
    message(paste0("❌ '", folder.name, "' does NOT exist at: ", folder.path))
  }
}

# Check each folder
check_folder("input.folder", input.folder)
check_folder("map.folder", map.folder)

# Check input files
if (dir.exists(input.folder)) {
  files <- list.files(input.folder, pattern = "\\.(sl4|har)$", ignore.case = TRUE, full.names = FALSE)
  if (length(files) > 0) {
    cat("Available files:", paste(files, collapse = ","), "\n")
  }
}

# Extract Data
auto_gtap_data(
  experiment = experiment,
  process_sl4_vars = NULL, 
  process_har_vars = NULL,
  mapping_info = "GTAPv7",
  sl4_mapping_info = NULL,
  har_mapping_info = NULL,
  sl4_convert_unit = NULL,
  har_convert_unit = NULL,
  region_select = NULL,
  sector_select = NULL,
  subtotal_level = FALSE,
  input_path = input.folder,
  map_path = map.folder,
  sl4_extract_method = "get_data_by_var",
  har_extract_method = "get_data_by_var",
  subtotal_level = TRUE,
  plot_data = TRUE,
  output_formats = list(
    "csv" = "no",
    "stata" = "no",
    "rds" = "no",
    "txt" = "no"))

Solution 3

Show/Hide
  1. Once the solution 2 is complete, check whether sl4.plot.data and har.plot.data appear in your R environment.
    If they do, it means the extraction was successful using default settings. In that case, the root of the problem may be a mismatch when filtering data by “Variable”, “Region”, or “Sector” in the OutputMapping.xlsx file.

    • Other potential issues may include:

      • The data extraction method used in your code. Try modifying it as follows:
        • sl4_extract_method = "get_data_by_var"
        • har_extract_method = "get_data_by_var"
      • Your model includes subtotal_effects, but this was not enabled. Add this line to your code:
        • subtotal_level = TRUE
  2. If the output is still empty, try reinstalling the package.

  3. After reinstalling, if the issue persists, try importing the raw data directly using the HARplus package.
    For more details, see: https://bodysbobb.github.io/HARplus/articles/introduction.html

Plot Dimensions

Common Issue:

  • The plot output is not aesthetically pleasing—too dense, too small, or too large.

  • The plot dimensions do not match expectations.

Solution 1

Show/Hide
  1. Adjust the width and height parameters in the following code.
my_export_config <- create_export_config(
  width = 10, # Width in inches
  height = 6, # Height in inches
  dpi = 300, # Resolution in dots per inch
  units = "in" # Units for width and height
)
  1. Pass the customized my_export_config to your plot function, while keeping all other settings (...) unchanged, as shown in the example below:
comparison_plot(...,
                export_config = my_export_config
                )

Plot Order and Rearrangement

Common Issue:

  • Want to change the display order in plots, such as showing EXP2 before EXP1, or SEAsia before Oceania.

Solution 1

Show/Hide

To customize the sorting, use the following command:

# Using the function
sort_sl4_plot <- sort_plot_data(
  sl4.plot.data,
  sort_columns = list(
    Experiment = c("EXP2", "EXP1"), # Column Name = Sorting Order
    Region = c("SEAsia", "Oceania")
    ),
  sort_by_value_desc = NULL
)
💡 Tip
This will:
<ul>
  <li>Sort by multiple columns simultaneously for precise output control</li>
  <li>Apply consistent sorting across all data frames within a data list</li>
</ul>

Missing Plot Outputs

Solution 1

Show/Hide

Ensure that the export parameters are set to TRUE in the plot function:

comparison_plot(...,
                 export_picture = TRUE,
                 export_as_pdf = "merged") # (merged will combine all plots into one PDF file)

Solution 2

Show/Hide
  • Make sure you have defined the correct output_path in the plot function.
  • Check the R console to see if any errors occurred while generating the plots. If the plot was successfully created and saved, the R console should indicate the output directory.
  • If it still doesn’t work, try changing the directory to a local folder. Sometimes, issues occur due to directory permissions or cloud-synced folders.
  • Restart the R session and try again.

Convert Different Units

Common Issue:

  • The data units are not in the desired format.
  • Monetary values are in units other than USD.
  • You want to convert specific units that are not automatically handled.

Solution 1

Show/Hide

You can convert all units across all data frames within the data list by using the following code:

your_data <- sl4.plot.data   # Change this to your data list name

your_data <- convert_units(change_unit_from = c("BAHT", "million USD"),
                           change_unit_to = c("USD", "billion USD"),
                           adjustment = c("*34.5", "/1000"))
Explanation

What does this code do?

  • Converts BAHT to USD by multiplying the values by 34.5.

  • Converts million USD to billion USD by dividing the values by 1,000.

Parameters:

  • change_unit_from: The original unit name to be changed in the "Unit" column.
    If your dataset does not yet include a "Unit" column, please refer to adding unit and description columns.

  • change_unit_to: The new unit name to be recorded in the "Unit" column.

  • adjustment: The mathematical operation used to transform the values.
    Accepts operators such as /, *, +, or -.

Missing Unit and Description

Common Issue:

  • Missing "Description" and "Unit" columns in the data list.

  • The "Description" and "Unit" columns are not correctly defined for each variable.

Solution 1

Show/Hide

The easiest way is to re-run 1.ProjectSetup.R file and ensure that you have define:

  • OutputMapping.xlsx file in the /map folder, specifically in column "Description" and "Unit" in sheet “SL4File” and “HARFile”.

  • Make sure that you define the mapping_info parameter as Yes or mix

mapping_df <- data.frame(
  Variable = c("qgdp", "EV", "ppriv"),
  Description = c("Real GDP Index", "Welfare Equivalents", "Consumer Price Index"),
  Unit = c("Percent", "million USD", "percent"),
  stringsAsFactors = FALSE
)

datasets <- add_mapping_info(mapping_df, external_map = mapping_df, mapping = "Yes")
Note: Use ?add_mapping_info to understand the meaning of mapping.