Skip to content

Instantly share code, notes, and snippets.

@mustafaascha
Created January 19, 2019 22:07
Show Gist options
  • Save mustafaascha/0877ed260530af180793fbc56c5e833a to your computer and use it in GitHub Desktop.
Save mustafaascha/0877ed260530af180793fbc56c5e833a to your computer and use it in GitHub Desktop.
Format PubMed file exports
pubmed_cv <- function(fl_nm) {
library(tidyverse)
readLines("pubmed_result.txt") %>%
(function(z) z[z != ""]) %>%
(function(cv) {
grep("^[0-9]+?:", trimws(cv)) %>%
list(
beginnings = .,
ends = compose(as.numeric, na.omit)(c(lead(.) - 1, length(cv)))
) %>%
pmap_chr(~ reduce(cv[.x:.y], paste, .init = ""))
}) %>%
trimws()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment