-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
124 changed files
with
6,773 additions
and
131,786 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Package: datadrivencv | ||
Type: Package | ||
Title: Templates and helper functions for building a CV with spreadsheets | ||
Version: 0.1.0 | ||
URL: http://nickstrayer.me/datadrivencv, https://github.com/nstrayer/datadrivencv | ||
Author: Nick Strayer | ||
Maintainer: Nick Strayer <[email protected]> | ||
Description: Separates the CV format from the content using spreadsheets, RMarkdown, and Pagedown. Built to allow easy out-of-the-box behavior, but also to allow you to go beyond the defaults with customization and lack of lock-in to a given format. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Imports: | ||
dplyr, | ||
tidyr, | ||
glue, | ||
readr, | ||
googlesheets4, | ||
lubridate, | ||
purrr, | ||
stringr, | ||
magrittr, | ||
pagedown, | ||
fs, | ||
icon (>= 0.1.0), | ||
whisker | ||
RoxygenNote: 7.0.2 | ||
Roxygen: list(markdown = TRUE) | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
testthat (>= 2.1.0) | ||
VignetteBuilder: knitr | ||
Remotes: | ||
ropenscilabs/icon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2020 | ||
COPYRIGHT HOLDER: Nick Strayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2020 Nick Strayer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export("%>%") | ||
export(build_network_logo) | ||
export(use_csv_data_storage) | ||
export(use_datadriven_cv) | ||
importFrom(magrittr,"%>%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#' Build interactive network logo | ||
#' | ||
#' Constructs a network based on your position data to be used as a logo. | ||
#' Interactive in HTML version and static in the PDF version. Notes are entries, | ||
#' colored by section and connected if they occurred in the same year | ||
#' | ||
#' @param position_data position data from your `CV_Printer` class. | ||
#' | ||
#' @return Interactive force-directed layout network of your CV data | ||
#' @export | ||
build_network_logo <- function(position_data){ | ||
|
||
positions <- position_data %>% | ||
dplyr::mutate( | ||
id = dplyr::row_number(), | ||
title = stringr::str_remove_all(title, '(\\(.+?\\))|(\\[)|(\\])'), | ||
section = stringr::str_replace_all(section, "_", " ") %>% stringr::str_to_title() | ||
) | ||
|
||
combination_indices <- function(n){ | ||
rep_counts <- (n:1) - 1 | ||
dplyr::tibble( | ||
a = rep(1:n, times = rep_counts), | ||
b = purrr::flatten_int( purrr::map(rep_counts, ~{tail(1:n, .x)}) ) | ||
) | ||
} | ||
current_year <- lubridate::year(lubridate::ymd(Sys.Date())) | ||
edges <- positions %>% | ||
dplyr::select(id, start_year, end_year) %>% | ||
dplyr::mutate( | ||
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_year, end_year){ | ||
dplyr::tibble( | ||
year = start_year:end_year, | ||
id = id | ||
) | ||
}) %>% | ||
dplyr::group_by(year) %>% | ||
tidyr::nest() %>% | ||
dplyr::rename(ids_for_year = data) %>% | ||
purrr::pmap_dfr(function(year, ids_for_year){ | ||
combination_indices(nrow(ids_for_year)) %>% | ||
dplyr::transmute( | ||
year = year, | ||
source = ids_for_year$id[a], | ||
target = ids_for_year$id[b] | ||
) | ||
}) | ||
|
||
network_data <- list(nodes = dplyr::select(positions, -in_resume,-timeline), | ||
edges = edges) %>% | ||
jsonlite::toJSON() | ||
|
||
viz_script <- readr::read_file(system.file("js/cv_network.js", package = "datadrivencv")) | ||
|
||
glue::glue( | ||
"<script id = \"data_for_network\" type = \"application/json\">", | ||
"{network_data}", | ||
"</script>", | ||
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.min.js\"></script>", | ||
"<svg style = \"width: 100%; height:320px; margin-top: -125px;\" id = \"cv_network_viz\"></svg>", | ||
"<script>", | ||
"{viz_script}", | ||
"</script>" | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Use CSVs for storing data | ||
#' | ||
#' Sets up examples of the four CSVs needed for building CV | ||
#' | ||
#' | ||
#' @param folder_name Name of the folder you want csvs stored in relative to current working directory | ||
#' @inheritParams use_ddcv_template | ||
#' | ||
#' @return A new folder `<folder_name>/` with `entries.csv`, `text_blocks.csv`, `language_skills.csv`, and `contact_info.csv` in it. | ||
#' working directory. | ||
#' | ||
#' @examples | ||
#' | ||
#' # Make a temp directory for placing files | ||
#' # This would be a real location for a typical situation | ||
#' temp_dir <- fs::dir_create(fs::path(tempdir(), "cv_w_csvs")) | ||
#' | ||
#' datadrivencv::use_csv_data_storage( | ||
#' folder_name = fs::path(temp_dir, "csv_data"), | ||
#' create_output_dir = TRUE | ||
#' ) | ||
#' | ||
#' list.files(fs::path(temp_dir, "csv_data")) | ||
#' | ||
#' @export | ||
use_csv_data_storage <- function(folder_name = "data", create_output_dir = TRUE){ | ||
|
||
for(csv_file in c("entries.csv", "text_blocks.csv", "language_skills.csv","contact_info.csv" )){ | ||
use_ddcv_template( | ||
file_name = csv_file, | ||
output_dir = folder_name, | ||
create_output_dir = create_output_dir, | ||
warn_about_no_change = TRUE | ||
) | ||
} | ||
|
||
print(paste("Copied CSVs to ", folder_name)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#' Use Data Driven CV template | ||
#' | ||
#' Sets up the `.Rmd` file for a data-driven cv in current working directory. | ||
#' Also adds css file for current CV so style can be custommized. | ||
#' | ||
#' | ||
#' | ||
#' @param full_name Your full name, used in title of document and header | ||
#' @param data_location Path of the spreadsheets holding all your data. This can | ||
#' be either a URL to a google sheet with multiple sheets containing the four | ||
#' data types or a path to a folder containing four `.csv`s with the neccesary | ||
#' data. See \code{\link{use_csv_data_storage()}} for help setting up these | ||
#' `.csv`s. | ||
#' @param pdf_location What location will the PDF of this CV be hosted at? | ||
#' @param html_location What location will the HTML version of this CV be hosted | ||
#' at? | ||
#' @param source_location Where is the code to build your CV hosted? | ||
#' @param open_files Should the added files be opened after creation? | ||
#' @param which_files What files should be placed? Takes a vector of possible | ||
#' values `c("cv.rmd", "dd_cv.css", "render_cv.r", "cv_printing_functions.r")` | ||
#' or `"all"` for everything. This can be used to incrementally update the | ||
#' printing functions or CSS without loosing customizations you've made to | ||
#' other files. | ||
#' @param output_dir Where should the files be placed? Defaults to your current working directory | ||
#' @param use_network_logo Should logo be an interactive network based on your | ||
#' CV data? Note that this uses the function | ||
#' \code{\link{build_network_logo()}} so will introduce a dependency on this | ||
#' package. | ||
#' @inheritParams use_ddcv_template | ||
#' | ||
#' @return `cv.rmd`, `dd_cv.css`, `render_cv.r`, and `cv_printing_functions.r` | ||
#' written to the current working directory. | ||
#' | ||
#' @examples | ||
#' | ||
#' # Make a temp directory for placing files | ||
#' # This would be a real location for a typical situation | ||
#' temp_dir <- fs::dir_create(fs::path(tempdir(), "my_cv")) | ||
#' | ||
#' use_datadriven_cv( | ||
#' full_name = "Nick Strayer", | ||
#' data_location = "https://docs.google.com/spreadsheets/d/14MQICF2F8-vf8CKPF1m4lyGKO6_thG-4aSwat1e2TWc", | ||
#' pdf_location = "https://github.com/nstrayer/cv/raw/master/strayer_cv.pdf", | ||
#' html_location = "nickstrayer.me/cv/", | ||
#' source_location = "https://github.com/nstrayer/cv", | ||
#' output_dir = temp_dir, | ||
#' open_files = FALSE | ||
#' ) | ||
#' | ||
#' # Files should be where they were requested | ||
#' list.files(temp_dir) | ||
#' | ||
#' @export | ||
use_datadriven_cv <- function(full_name = "Sarah Arcos", | ||
data_location = system.file("sample_data/", package = "datadrivencv"), | ||
pdf_location = "https://github.com/nstrayer/cv/raw/master/strayer_cv.pdf", | ||
html_location = "nickstrayer.me/datadrivencv/", | ||
source_location = "https://github.com/nstrayer/datadrivencv", | ||
which_files = "all", | ||
output_dir = getwd(), | ||
create_output_dir = FALSE, | ||
use_network_logo = TRUE, | ||
open_files = TRUE){ | ||
|
||
if(is.character(which_files) && which_files == "all"){ | ||
which_files <- c("cv.rmd", "dd_cv.css", "render_cv.r", "cv_printing_functions.r") | ||
} | ||
# Make case-insensitive | ||
which_files <- tolower(which_files) | ||
|
||
if("cv.rmd" %in% which_files){ | ||
# Sets the main Rmd template | ||
use_ddcv_template( | ||
file_name = "cv.rmd", | ||
params = list( | ||
full_name = full_name, | ||
data_location = data_location, | ||
pdf_location = pdf_location, | ||
html_location = html_location, | ||
source_location = source_location, | ||
use_network_logo = use_network_logo | ||
), | ||
output_dir = output_dir, | ||
create_output_dir = create_output_dir, | ||
open_after_making = open_files | ||
) | ||
} | ||
|
||
if("dd_cv.css" %in% which_files){ | ||
# Place the css as well | ||
use_ddcv_template( | ||
file_name = "dd_cv.css", | ||
output_dir = output_dir, | ||
create_output_dir | ||
) | ||
} | ||
|
||
if("render_cv.r" %in% which_files){ | ||
use_ddcv_template( | ||
file_name = "render_cv.r", | ||
output_dir = output_dir, | ||
create_output_dir, | ||
open_after_making = open_files | ||
) | ||
} | ||
|
||
if("cv_printing_functions.r" %in% which_files){ | ||
use_ddcv_template( | ||
file_name = "cv_printing_functions.r", | ||
output_dir = output_dir, | ||
create_output_dir | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#' Use template file from package | ||
#' | ||
#' @param file_name Name of file from templates to use: e.g. `cv.rmd`. | ||
#' @param params Parameters used to fill in `whisker` template | ||
#' @param output_file_name Name of file after being placed. | ||
#' @param output_dir Directory location for output to be placed in. | ||
#' @param create_output_dir If the requested output directory is missing should it be created? | ||
#' @param warn_about_no_change If there is no change between the new file and what was already there, should a warning be issued? | ||
#' @param open_after_making Should the file be opened after it has been written? | ||
#' | ||
#' @return NULL | ||
use_ddcv_template <- function( | ||
file_name, | ||
params = NULL, | ||
output_file_name = file_name, | ||
output_dir = getwd(), | ||
create_output_dir = FALSE, | ||
warn_about_no_change = TRUE, | ||
open_after_making = FALSE){ | ||
output_dir_missing <- !fs::dir_exists(output_dir) | ||
|
||
if(output_dir_missing & create_output_dir){ | ||
fs::dir_create(output_dir) | ||
} else | ||
if(output_dir_missing & !create_output_dir) { | ||
stop(glue::glue("The requested output directory: {output_dir} doesn't exist. Either set create_output_dir = TRUE or manually make directory.")) | ||
} | ||
|
||
|
||
template_loc <- fs::path(system.file("templates/", package = "datadrivencv"), file_name) | ||
output_loc <- fs::path(output_dir, output_file_name) | ||
|
||
template_text <- readr::read_file(template_loc) | ||
|
||
if(!is.null(params)){ | ||
template_text <- whisker::whisker.render(template_text, data = params) | ||
} | ||
|
||
# Check if file exists already | ||
already_exists <- fs::file_exists(output_loc) | ||
if(already_exists){ | ||
# Check if the two files are identical | ||
no_changes_made <- readr::read_file(output_loc) == template_text | ||
|
||
if(no_changes_made & warn_about_no_change){ | ||
warning(glue::glue("{file_name} already exists and there are no differences with the current version.")) | ||
} | ||
} | ||
|
||
readr::write_file(template_text, output_loc) | ||
|
||
# Open the file if requested | ||
if(open_after_making){ | ||
if (rstudioapi::isAvailable() && rstudioapi::hasFun("navigateToFile")) { | ||
rstudioapi::navigateToFile(output_loc) | ||
} else { | ||
utils::file.edit(output_loc) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#' Pipe operator | ||
#' | ||
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. | ||
#' | ||
#' @name %>% | ||
#' @rdname pipe | ||
#' @keywords internal | ||
#' @export | ||
#' @importFrom magrittr %>% | ||
#' @usage lhs \%>\% rhs | ||
NULL |
Oops, something went wrong.