#Run List
#2022 01 27
#2022 01 31
#Rewritten to inlcude simplified code at each stage
#Ed Lefley

#Run order of R Scripts for comlpete import from XLSX file to all.

#Load all R Packages if running in the Cloud, also change all WD
#ource("Install_R_Packages.R")

#1 Source Files - Code unchanged but now includes a clean up for the import files that are surplus
st <- sys.time()
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("Merging_All_XLSX_to_CSV_08.R")
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Remove_Import.R")
##Output dataframe: WoS_All_Record

#2 Regex Clean - change here any regex errors from later on
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Regex_Clean.R")
##Output dataframe WoS_All and WoS_All_D (joined to WoS_All)

#3 Address Split from Authors
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Address_Split.R")
##Output dataframe WoS_All_Addresses 

#4 Split Addresses by semicolon and comma
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Vector.R")
##Output dataframes: unique: {WoS_AAU, WoS_U_D} all: {WoS_AA, WoS_A_D}, WoS_Address_Vector for Combined Addresses

#5 Rearrange Addresses
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Rearrange_Addresses_Use.R")
##Output dataframe: WoS_A_REV_DD and WoS_U_REV_DD

#Clean out department information and standardise addresses
#Split off reversed country, state, city, postcode and then add back to the 

#6 Reorder & Join the new list to the original
setwd("C:/Users/Ed/OneDrive/PhD/R/SLR_2022_02")
source("2022_01_31_Reorder_and_Clean_All.R")
#85mins run
##Output dataframes WoS_AA_All & WoS_AA_All_U (Australia only), WoS_Address_All (Global)

#7 Geocode these shorter lists
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Country.R")
##Output dataframe Country_List_C (country only), Country_List_C_NN (No US postcodes), Country_List_C_U (unique countries)
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_CSC.R")
##Output dataframe CSC (Country, State, City) unique, all and Australia only (CSC_C_NN_U_A)
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_Combing_Addresses.R")

##Output dataframe Geocode_this, Geocoded Addressses, Combined_Addresses

st2 <- Sys.time()
#8 TH Allocation
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2022_01_31_TH_IFa.R")
##Output dataframe WoS_All_Record_TH_SS and WoS_All_Record
#Allow at least 51hrs
et <- Sys.time()

tt <- 24*(et-st2)

#Attach Geocode to the full list using Find and Replace

#Then find and Replace over the original affiliation details
#setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
#source("2021_11_02_Merging_addresses.R")
#source("2021_11_09_Combing_Addresses.R")

#Entropy Calc
setwd("C:/Users/Ed/OneDrive/PhD/R/TH_2022_02")
source("2021_12_10_Entropy.R")
