diff --git a/R/build_network_logo.R b/R/build_network_logo.R index 1e5ece0..9628494 100644 --- a/R/build_network_logo.R +++ b/R/build_network_logo.R @@ -26,16 +26,14 @@ build_network_logo <- function(position_data){ } current_year <- lubridate::year(lubridate::ymd(Sys.Date())) edges <- positions %>% - dplyr::select(id, start, end) %>% + dplyr::select(id, start_year, end_year) %>% dplyr::mutate( - end = ifelse( - tolower(end) == "Current" | is.na(end) | end == "N/A", current_year, - end), - start = ifelse(start == "N/A", end, start) + end_year = ifelse(end_year > current_year, current_year, end_year), + start_year = ifelse(start_year > current_year, current_year, start_year) ) %>% - purrr::pmap_dfr(function(id, start, end){ + purrr::pmap_dfr(function(id, start_year, end_year){ dplyr::tibble( - year = start:end, + year = start_year:end_year, id = id ) }) %>% @@ -51,7 +49,7 @@ build_network_logo <- function(position_data){ ) }) - network_data <- list(nodes = dplyr::select(positions, -in_resume,-end_num,-timeline), + network_data <- list(nodes = dplyr::select(positions, -in_resume,-timeline), edges = edges) %>% jsonlite::toJSON() diff --git a/inst/templates/CV_printing_functions.R b/inst/templates/CV_printing_functions.R index a730003..b1a4d24 100644 --- a/inst/templates/CV_printing_functions.R +++ b/inst/templates/CV_printing_functions.R @@ -37,13 +37,13 @@ create_CV_object <- function(data_location, options(gargle_oauth_cache = ".secrets") } - cv$entries_data <- googlesheets4::read_sheet(data_location, sheet = "entries", skip = 1) %>% - # Google sheets loves to turn columns into list ones if there are different types - dplyr::mutate_if(is.list, purrr::map_chr, as.character) - - cv$skills <- googlesheets4::read_sheet(data_location, sheet = "language_skills", skip = 1) - cv$text_blocks <- googlesheets4::read_sheet(data_location, sheet = "text_blocks", skip = 1) - cv$contact_info <- googlesheets4::read_sheet(data_location, sheet = "contact_info", skip = 1) + read_gsheet <- function(sheet_id){ + googlesheets4::read_sheet(data_location, sheet = sheet_id, skip = 1, col_types = "c") + } + cv$entries_data <- read_gsheet(sheet_id = "entries") + cv$skills <- read_gsheet(sheet_id = "language_skills") + cv$text_blocks <- read_gsheet(sheet_id = "text_blocks") + cv$contact_info <- read_gsheet(sheet_id = "contact_info") } else { # Want to go old-school with csvs? cv$entries_data <- readr::read_csv(paste0(data_location, "entries.csv"), skip = 1) @@ -53,8 +53,21 @@ create_CV_object <- function(data_location, } - # This year is assigned to the end date of "current" events to make sure they get sorted later. - future_year <- lubridate::year(lubridate::ymd(Sys.Date())) + 10 + extract_year <- function(dates){ + date_year <- stringr::str_extract(dates, "(20|19)[0-9]{2}") + date_year[is.na(date_year)] <- lubridate::year(lubridate::ymd(Sys.Date())) + 10 + + date_year + } + + parse_dates <- function(dates){ + + date_month <- stringr::str_extract(dates, "(\\w+|\\d+)(?=(\\s|\\/|-)(20|19)[0-9]{2})") + date_month[is.na(date_month)] <- "1" + + paste("1", date_month, extract_year(dates), sep = "-") %>% + lubridate::dmy() + } # Clean up entries dataframe to format we need it for printing cv$entries_data %<>% @@ -66,21 +79,22 @@ create_CV_object <- function(data_location, ) %>% dplyr::mutate( description_bullets = paste0("- ", description_bullets), + start = ifelse(start == "NULL", NA, start), + end = ifelse(end == "NULL", NA, end), + start_year = extract_year(start), + end_year = extract_year(end), no_start = is.na(start), has_start = !no_start, no_end = is.na(end), has_end = !no_end, - cur_end = tolower(end) %in% c("current", "now", ""), - end_num = ifelse (cur_end | no_end, future_year, end), timeline = dplyr::case_when( no_start & no_end ~ "N/A", no_start & has_end ~ as.character(end), - has_start & no_end ~ paste(start, "-", "Current"), + has_start & no_end ~ paste("Current", "-", start), TRUE ~ paste(end, "-", start) ) ) %>% - dplyr::select(-no_start, -has_start, -no_end, -has_end, -cur_end) %>% - dplyr::arrange(desc(end_num)) %>% + dplyr::arrange(desc(parse_dates(end))) %>% dplyr::mutate_all(~ ifelse(is.na(.), 'N/A', .)) cv @@ -183,7 +197,7 @@ print_skill_bars <- function(cv, out_of = 5, bar_color = "#969696", bar_backgrou >{skill}" } cv$skills %>% - dplyr::mutate(width_percent = round(100*level/out_of)) %>% + dplyr::mutate(width_percent = round(100*as.numeric(level)/out_of)) %>% glue::glue_data(glue_template) %>% print() diff --git a/tests/date_options/setup_test.R b/tests/date_options/setup_test.R new file mode 100644 index 0000000..12350f4 --- /dev/null +++ b/tests/date_options/setup_test.R @@ -0,0 +1,12 @@ +library(here) + + +datadrivencv::use_datadriven_cv( + full_name = "Testing McTester", + # data_location = "https://docs.google.com/spreadsheets/d/1SC8dKPlPZDA1MECZr8xlJPitjWQ3AV4eXrPvnlNv7m8/", + data_location = "https://docs.google.com/spreadsheets/d/14MQICF2F8-vf8CKPF1m4lyGKO6_thG-4aSwat1e2TWc", + output_dir = here("tests/date_options"), + open_files = FALSE, + which_files = "all" + # which_files = c("cv_printing_functions.r") +)