Greetings,
I am having a problem with the following codes.
These are the codes I'm using.
library(tidyverse)
library(retrosheet)
download_retrosheet <- function(season) {
get zip file from retrosheet website
download.file(
url = paste0(
"http://www.retrosheet.org/events/", season, "eve.zip"),
destfile = file.path("retrosheet", "zipped",
paste0(season, "eve.zip"))
)
}
unzip_retrosheet <- function(season) {
unzip retrosheet files
unzip(file.path("retrosheet", "zipped",
paste0(season, "eve.zip")),
exdir = file.path("retrosheet", "unzipped"))
}
create_csv_file <- function(season) {
shell("cwevent -y 2000 2000TOR.EVA > 2000TOR.bev")
wd <- getwd()
setwd("retrosheet/unzipped")
cmd <- paste0("cwevent -y ", season, " -f 0-96 ",
season, ".EV", " > all", season, ".csv")
message(cmd)
if (.Platform$OS.type == "unix") {
system(cmd)
} else {
shell(cmd)
}
setwd(wd)
}
create_csv_roster <- function(season) {
creates a CSV file of the rosters
rosters <- list.files(
path = file.path("retrosheet", "unzipped"),
pattern = paste0(season, ".ROS"),
full.names = TRUE)
rosters %>%
map_df(read_csv,
col_names = c("PlayerID", "LastName", "FirstName",
"Bats", "Pitches", "Team")) %>%
write_csv(path = file.path("retrosheet",
"unzipped",
paste0("roster", season, ".csv")))
}
cleanup <- function() {
removes retrosheet files not needed
files <- list.files(
path = file.path("retrosheet", "unzipped"),
pattern = "(.EV|.ROS|TEAM*)",
full.names = TRUE
)
unlink(files)
zips <- list.files(
path = file.path("retrosheet", "zipped"),
pattern = "*.zip",
full.names = TRUE
)
unlink(zips)
}
parse_retrosheet_pbp <- function(season) {
download_retrosheet(season)
unzip_retrosheet(season)
create_csv_file(season)
create_csv_roster(season)
cleanup()
}
parse_retrosheet_pbp(1950)
After running the function parse_retrosheet_pbp(1950), Rstudio is giving me the following message:
cwevent -y 1950 -f 0-96 1950*.EV* > all1950.csv
'cwevent' is not recognized as an internal or external command,
operable program or batch file.
Warning messages:
1: In download.file(url = paste0("http://www.retrosheet.org/events/", :
URL http://www.retrosheet.org/events/1950eve.zip: cannot open destfile 'retrosheet/zipped/1950eve.zip', reason 'No such file or directory'
2: In download.file(url = paste0("http://www.retrosheet.org/events/", :
download had nonzero exit status
3: In unzip(file.path("retrosheet", "zipped", paste0(season, "eve.zip")), :
error 1 in extracting from zip file
4: In shell(cmd) :
'cwevent -y 1950 -f 0-96 1950*.EV* > all1950.csv' execution failed with error code 1