Skip to content

Commit

Permalink
Merge pull request nstrayer#2 from nstrayer/migrating_to_glue_data
Browse files Browse the repository at this point in the history
Migrating to glue data
  • Loading branch information
Nick Strayer authored Oct 2, 2019
2 parents 59b669a + c8f26c2 commit 44a98dc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 50 deletions.
2 changes: 2 additions & 0 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Aside
# When in export mode the little dots are unaligned, so fix that.
if(PDF_EXPORT){
cat("View this CV online with links at _nickstrayer.me/cv_")
} else {
cat("[<i class='fas fa-download'></i> Download a PDF of this CV](https://github.com/nstrayer/cv/raw/master/strayer_cv.pdf)")
}
```

Expand Down
5 changes: 3 additions & 2 deletions index.html

Large diffs are not rendered by default.

91 changes: 46 additions & 45 deletions parsing_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,61 @@ sanitize_links <- function(text){
text <<- text %>% str_replace(fixed(link_from_text), new_text)
})
}

text
}


# Takes a single row of dataframe corresponding to a position
# turns it into markdown, and prints the result to console.
build_position_from_df <- function(pos_df){

missing_start <- pos_df$start == 'N/A'
dates_same <- pos_df$end == pos_df$start

if(any(c(missing_start,dates_same))){
timeline <- pos_df$end
} else {
timeline <- glue('{pos_df$end} - {pos_df$start}')
# Take entire positions dataframe and removes the links
# in descending order so links for the same position are
# right next to eachother in number.
strip_links_from_cols <- function(data, cols_to_strip){
for(i in 1:nrow(data)){
for(col in cols_to_strip){
data[i, col] <- sanitize_links(data[i, col])
}
}

descriptions <- pos_df[str_detect(names(pos_df), 'description')] %>%
as.list() %>%
map_chr(sanitize_links)

# Make sure we only keep filled in descriptions
description_bullets <- paste('-', descriptions[descriptions != 'N/A'], collapse = '\n')

glue(
"### {sanitize_links(pos_df$title)}
{pos_df$loc}
{pos_df$institution}
{timeline}
{description_bullets}
"
) %>% print()
data
}

# Takes nested position data and a given section id
# and prints all the positions in that section to console
# Take a position dataframe and the section id desired
# and prints the section to markdown.
print_section <- function(position_data, section_id){
position_data %>%
filter(section == section_id) %>%
mutate(id = 1:n()) %>%
mutate_all(fill_nas) %>%
arrange(desc(end)) %>%
nest(data = c(-id, -section)) %>%
pull(data) %>%
purrr::walk(build_position_from_df)
mutate(id = 1:n()) %>%
pivot_longer(
starts_with('description'),
names_to = 'description_num',
values_to = 'description',
values_drop_na = TRUE
) %>%
group_by(id) %>%
mutate(
descriptions = list(description)
) %>%
ungroup() %>%
filter(description_num == 'description_1') %>%
mutate(
timeline = ifelse(
is.na(start) | start == end,
end,
glue('{end} - {start}')
),
description_bullets = map_chr(descriptions, ~paste('-', ., collapse = '\n')),
) %>%
strip_links_from_cols(c('title', 'description_bullets')) %>%
mutate_all(~ifelse(is.na(.), 'N/A', .)) %>%
glue_data(
"### {title}",
"\n\n",
"{loc}",
"\n\n",
"{institution}",
"\n\n",
"{timeline}",
"\n\n",
"{description_bullets}",
"\n\n\n",
)
}

fill_nas <- function(column){
ifelse(is.na(column), 'N/A', column)
}
1 change: 0 additions & 1 deletion resume.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ source('parsing_functions.R')
position_data <- read_csv('positions.csv') %>%
filter(in_resume) %>%
mutate(
id = 1:n(),
# Build some custom sections by collapsing others
section = case_when(
section %in% c('research_positions', 'industry_positions') ~ 'positions',
Expand Down
4 changes: 2 additions & 2 deletions resume.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="Nick Strayer" />
<meta name="date" content="2019-10-01" />
<meta name="date" content="2019-10-02" />
<title>Nick Strayer’s Resume&quot;</title>

<style type="text/css">
Expand Down Expand Up @@ -30296,7 +30296,7 @@ <h2>More info</h2>
<h2>Disclaimer</h2>
<p>Made w/ <a href="https://github.com/rstudio/pagedown"><strong>pagedown</strong></a>.</p>
<p>Source code: <a href="https://github.com/nstrayer/cv">github.com/nstrayer/cv</a>.</p>
<p>Last updated on 2019-10-01.</p>
<p>Last updated on 2019-10-02.</p>
</div>
</div>
<div id="main" class="section level1">
Expand Down

0 comments on commit 44a98dc

Please sign in to comment.