Skip to content

Instantly share code, notes, and snippets.

@benjaminrobinson
Created April 28, 2020 21:41
Show Gist options
  • Save benjaminrobinson/303e238e309404101c0ffb43ca4d0ebe to your computer and use it in GitHub Desktop.
Save benjaminrobinson/303e238e309404101c0ffb43ca4d0ebe to your computer and use it in GitHub Desktop.
library(tidyverse)
getWikiNFLDraft <- function(x, method = 'df') {
if (method == 'copy') {
paste0('https://en.wikipedia.org/wiki/', x, '_NFL_Draft') %>%
read_html %>%
html_table(fill = TRUE) %>%
.[[5]] %>%
select(-1, -Notes, -Conf.) %>%
setNames(c('round', 'pick', 'team', 'name', 'position', 'school')) %>%
mutate(
name = sub(" \\†", "", name),
name = sub(" [*]", "", name),
name = sub(" Jr.", "", name),
name = sub(" III", "", name),
pick = sub("[*]", "", pick),
round = sub("[*]", "", round)
) %>%
filter(!grepl("forfeit", name)) %>%
mutate_all(~ str_squish(.)) %>%
select(round, pick, name, position, school, team) %>%
write.table(
.,
"clipboard-20000",
sep = "\t",
row.names = FALSE,
col.names = FALSE
)
} else{
paste0('https://en.wikipedia.org/wiki/', x, '_NFL_Draft') %>%
read_html %>%
html_table(fill = TRUE) %>%
.[[5]] %>%
select(-1, -Notes, -Conf.) %>%
setNames(c('round', 'pick', 'team', 'name', 'position', 'school')) %>%
mutate(
name = sub(" \\†", "", name),
name = sub(" [*]", "", name),
name = sub(" Jr.", "", name),
name = sub(" III", "", name),
pick = sub("[*]", "", pick),
round = sub("[*]", "", round)
) %>%
filter(!grepl("forfeit", name)) %>%
mutate_all(~ str_squish(.)) %>%
select(round, pick, name, position, school, team)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment