### Main R Script for codes in folder "Codes/01_Country_level_GenAI_exposure"

# Cleaning workspace 
rm(list= ls())

# Paths -------------------------------------------------------------------

# Set package path ---

# Replace "your/path/to/Reproducibility_package" with the actual path to your package.

root_dir <- "C:/Users/wb519501/OneDrive - WBG/Desktop/RR_WLD_2025_528/files upload/v3/Reproducibility_package"

data_dir <- file.path(root_dir, "Data", "Raw")

cleaned_data_dir <- file.path(root_dir, "Data", "Cleaned")

graphs_dir <- file.path(root_dir, "Outputs")

# Libraries ---------------------------------------------------------------

install.packages("pacman")

require(pacman)

p_load(dplyr,            # For data manipulation
       tidyr,            # For reshaping data
       readxl,           # For reading .xlsx files
       haven,            # For reading .dta files
       stringr,          # For string manipulation
       fastDummies,      # For creating dummy variables
       WDI,              # For downloading World Development Indicators
       FNN,              # For fast k-nearest-neighbors
       purrr,            # For iterating results into a df  
       xtable,           # For converting R objects into LaTeX or HTML tables
       ggplot2,          # For plots (base package)
       ggthemes,         # Includes the theme used in the graphs
       ggrepel,          # For adding non-overlapping text labels to ggplots
       ggpubr,           # For arranging multiple ggplots into a single figure
       scales,           # For formatting numbers as percentages
       countrycode,      # For treating country names and codes 
       openxlsx          # For creating Excel workbooks programmatically   
       )

# R scripts ---------------------------------------------------------------

source(file.path(root_dir, "Codes", "01_Country_level_GenAI_exposure", "00-preparing-GenAI-exposure.R"))

source(file.path(root_dir, "Codes", "01_Country_level_GenAI_exposure", "01-estimating_ISCO_averages.R"))

source(file.path(root_dir, "Codes", "01_Country_level_GenAI_exposure", "02-knn-closest_match(ILO-exercise).R"))

source(file.path(root_dir, "Codes", "01_Country_level_GenAI_exposure", "03-graphs.R"))
