# Collect PITCHf/x (and other data from inning_all.xml files) from May 1st, 2012
dat <- scrape(start = "2013-08-01", end = "2013-08-01")
# OR, equivalently, use the game.ids argument
data(gids, package="pitchRx")
dat2 <- scrape(game.ids=gids[grep("2012_05_01", gids)])
#scrape PITCHf/x from Minnesota Twins 2011 season
twins11 <- gids[grepl("min", gids) & grepl("2011", gids)]
dat <- scrape(game.ids=twins11)
#Create SQLite database, then collect and store data in that database
library(dplyr)
my_db <- src_sqlite("my_db.sqlite3", create=T)
scrape(start = "2013-08-01", end = "2013-08-01", connect=my_db$con)
#simple example to demonstrate database query using dplyr
#note that 'num' and 'url' together make a key that allows us to join these tables
locations <- select(tbl(my_db, "pitches"), px, pz, des, num, url)
names <- select(tbl(my_db, "atbats"), pitcher_name, batter_name, num, url)
que <- inner_join(locations, filter(names, batter_name == "Paul Goldschmidt"))
que$query #refine sql query if you'd like
pitchfx <- collect(que) #submit query and bring data into R
# Collect PITCHf/x and other complementary data
files <- c("inning/inning_all.xml", "inning/inning_hit.xml",
"miniscoreboard.xml", "players.xml")
dat3 <- scrape(start = "2012-05-01", end = "2012-05-01", suffix = files)Run the code above in your browser using DataLab