Skip to content

Instantly share code, notes, and snippets.

@benfb
Created March 17, 2017 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfb/c2be996bcdbf0b1fa9f7f544fceb2934 to your computer and use it in GitHub Desktop.
Save benfb/c2be996bcdbf0b1fa9f7f544fceb2934 to your computer and use it in GitHub Desktop.
playername_lookup <- function(string=NULL) {
if (!exists("chadwick_player_lu_table")) {
print("Be patient, this may take a few seconds...")
print("Data courtesy of the Chadwick Bureau Register (https://github.com/chadwickbureau/register)")
id <- string
url <- "https://raw.githubusercontent.com/chadwickbureau/register/master/data/people.csv"
chadwick_player_lu_table <- read.csv(url)
assign("chadwick_player_lu_table", chadwick_player_lu_table, envir = .GlobalEnv)
x <- chadwick_player_lu_table %>%
filter(key_mlbam == id) %>%
select(name_first, name_last)
paste(as.character(x$name_first), as.character(x$name_last))
}
else {
id <- string
x <- chadwick_player_lu_table %>%
filter(key_mlbam == id) %>%
select(name_first, name_last)
paste(as.character(x$name_first), as.character(x$name_last))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment