scratch/save_WEF_taxonomy.R

# A macro to save the Forum's taxonomy as a data.tree within the package
# https://cran.r-project.org/web/packages/data.tree/vignettes/applications.html

library(janitor)
library(tidyverse)
library(readxl)
library(data.tree)
data <- read_excel(path = "scratch/WEF/skills-taxonomy.xlsx")

data <- data %>% clean_names()

# Give the columns more manageable names
data <- data %>% mutate(
  L1 = l1_skill,
  l1 = l1_definition,
  L2 = l2_skill,
  l2 = l2_definition,
  L3 = l3_skill,
  l3 = l3_definition,
  L4 = l4_skill,
  l4 = l4_definition
)

# Select the columns with useful info
# Names first (factors) and then definitions (tooltips?)
data <- data %>% select(L1, L2, L3, L4)

# Fill downwards as the Excel file's merged cells were made NA except at the top
# Don't do this for level 4 as some are intentionally blank
data <- data %>% fill(L1, L2, L3)

data[data=="NULL"] <- NA

data <- data %>% unite(col = "pathString", L1:L4, sep = "/", na.rm = TRUE, remove = FALSE)
data$pathString <- paste0("Forum Skills/", data$pathString)
wef.skills <- as.Node(data[,], na.rm = TRUE)
print(wef.skills)

save(wef.skills, file = "data/wef.skills.RData", version = 2)

remove(wef.skills)
remove(data)
markrayner/skillr documentation built on March 31, 2022, 9:07 p.m.