data-raw/user_group_validation.R

# PROJECT:  Wavelength
# AUTHOR:   A.Chafetz | USAID
# PURPOSE:  Create User Group review files
# LICENSE:  MIT
# DATE:     2021-09-29
# UPDATED:

# DEPENDENCIES ------------------------------------------------------------

  library(tidyverse)
  library(glamr)
  library(glue)
  library(googledrive)
  library(googlesheets4)


# GLOBAL VARIABLES --------------------------------------------------------

  load_secrets()

  gdrive_sht <- "1ICfvrnfDiJOS_P8CDWvdnGcKZlMHMQEuoOxs2lBwP1Y"

  gdrive_fldr <- "1XEN6w_pl5QoPSvyHCrCunIXtms_gVc-C"

# IMPORT ------------------------------------------------------------------

  df <- read_sheet(as_sheets_id(gdrive_sht), col_types = c(.default = "c"))

  df <- df %>%
    filter(role == "Field Team") %>%
    arrange(operatingunit, country, email) %>%
    mutate(operatingunit = ifelse(operatingunit == country, operatingunit, glue("{operatingunit}/{country}"))) %>%
    select(-c(country, group_name, role, date_added))

  temp_folder()

  ous  <- df %>%
    distinct(operatingunit) %>%
    mutate(ou_save = operatingunit %>%
                              str_replace("West Africa Region", "WAR") %>%
                              str_replace("Western Hemisphere Region", "WHR") %>%
                              str_replace("Democratic Republic of the Congo", "DRC") %>%
                              str_replace("/", "-") %>%
                              str_remove_all(" |'")
                              )


  walk2(.x = ous$operatingunit,
        .y = ous$ou_save,
        .f = ~ df %>%
                dplyr::filter(operatingunit == .x) %>%
                readr::write_csv(file.path(folderpath_tmp,
                                           glue("HFR_FY22_Email-and-Tableau-List_{.y}.csv")),
                                 na = ""))


  #grab files to upload
  ouputs <- list.files(folderpath_tmp, full.names = TRUE)

  walk(ouputs,
       ~ drive_upload(.x,
                      path = as_id(gdrive_fldr),
                      name = basename(.x),
                      type = "spreadsheet"))

  drive_ls(as_id(gdrive_fldr))  %>%
    drive_share(role = "writer", type = "domain", domain = "usaid.gov")
USAID-OHA-SI/Wavelength documentation built on March 24, 2023, 10:07 a.m.