-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseball-reference.R
45 lines (43 loc) · 1.08 KB
/
baseball-reference.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' Download daily updated WAR data for batters from Baseball-Reference
#'
#' @return An object with class `c("tbl_df", "tbl", "data.frame")` containing
#' batter WAR data.
#' @export
#'
#' @examples
#' \dontrun{
#' bref_war_daily_batter()
#' }
bref_war_daily_batter = function() {
url = "https://www.baseball-reference.com/data/war_daily_bat.txt"
data = data.table::fread(
url,
showProgress = FALSE,
data.table = FALSE,
na.strings = c("", "NULL")
)
class(data) = table_class()
return(data)
}
#' Download daily updated WAR data for pitchers from Baseball-Reference
#'
#' @return An object with class `c("tbl_df", "tbl", "data.frame")` containing
#' pitcher WAR data.
#' @export
#'
#' @examples
#' \dontrun{
#' bref_war_daily_pitcher()
#' }
bref_war_daily_pitcher = function() {
url = "https://www.baseball-reference.com/data/war_daily_pitch.txt"
data = data.table::fread(
url,
showProgress = FALSE,
data.table = FALSE,
na.strings = c("", "NULL")
)
class(data) = table_class()
return(data)
}
# https://www.baseball-reference.com/about/war_explained.shtml