R/wiki_genre_copy_clipboard.R

Defines functions wiki_genre_copy_clipboard

wiki_genre_copy_clipboard <- function(string) {
  # Given a string under the "Genre" heading on a Wikipedia page for an album, convert to
  # case appropriate to paste into iTunes, and copy to clipboard.
  #
  # Arguments:
  #   string {char} -- string of genres copied from Wikipedia
  #
  # Returns:
  #   Nothing
  string = gsub("\\[\\d+\\]", "|", string)
  string = gsub(" *, *", "|", string)
  string = strsplit(string, "\\|")[[1]]
  string = tools::toTitleCase(string)
  string = paste0(string, collapse = ", ")
  clip = pipe("pbcopy", "w")                       
  write.table(string, file = clip, row.names = FALSE, col.names = FALSE, quote = FALSE)
  close(clip)  
}
tsouchlarakis/rdoni documentation built on Sept. 16, 2019, 8:53 p.m.