#' Web Scrape for MLB Player Data
#'
#' @param name Player Name
#'
#' @return
#' @export
#'
#' @importFrom rvest html_table html_nodes
#' @importFrom xml2 read_html
#' @importFrom purrr map map_df as_mapper set_names
#' @importFrom tibble enframe
#' @import dplyr
#' @import tidyverse
#' @examples
#' name = 'Joey Votto'
#' JoeyVotto = MLB_Player(name)
MLB_Player <- function(name){
letter.url <- paste0('https://www.baseball-reference.com/', 'players/', letters[1:26])
MLB.Player.Data <- letter.url %>%
map(~ MLB_playerURL(.)) %>%
map_df(enframe)
Player.Data <- MLB.Player.Data[MLB.Player.Data$name == name,]
Player.url <- Player.Data[[2]]
html.read <- read_html(Player.url)
table <- as.data.frame(html_table(html.read))
table2 <- table[!(table$Year == table$Age),]
return(table2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.