Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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