/
client.R
356 lines (325 loc) · 33.4 KB
/
client.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#' @title American Soccer Analysis API Client
#' @description Class representing an active session connected to the American Soccer Analysis public API.
#' @details Does not take any arguments to initialize.
#' @export
AmericanSoccerAnalysis <- R6::R6Class("AmericanSoccerAnalysis",
public = list(
#' @field API_VERSION Latest API version.
API_VERSION = "v1",
#' @field MAX_API_LIMIT Maximum number of requests returned by the API by default.
MAX_API_LIMIT = 1000,
#' @field LEAGUES List of stylized league names.
LEAGUES = c("nwsl", "mls", "uslc", "usl1", "nasl", "mlsnp"),
#' @field base_url API base URL.
base_url = NULL,
#' @field players Data frame containing players from all leagues.
players = NULL,
#' @field teams Data frame containing teams from all leagues.
teams = NULL,
#' @field stadia Data frame containing stadia from all leagues.
stadia = NULL,
#' @field managers Data frame containing managers from all leagues.
managers = NULL,
#' @field referees Data frame containing referees from all leagues.
referees = NULL,
#' @field httr_configs Configs to pass on to all \code{httr} functions. See \href{https://www.rdocumentation.org/packages/httr/versions/1.4.2/topics/config}{documentation}.
httr_configs = list(),
#' @field latest_update_timestamp Keeps record of the latest update timestamp for queried data. Used to conditionally clear the client-side cache.
latest_update_timestamp = NULL,
#' @description Creates a new \code{AmericanSoccerAnalysis} object.
#' @param ... Configs to pass on to all \code{httr} functions. See \href{https://www.rdocumentation.org/packages/httr/versions/1.4.2/topics/config}{documentation}.
#' @return A new \code{AmericanSoccerAnalysis} object.
initialize = function(...) {
self$base_url <- glue::glue("https://app.americansocceranalysis.com/api/{self$API_VERSION}")
self$httr_configs <- list(...)
if (isFALSE(as.logical(Sys.getenv("NOT_CRAN", "false")))) {
self$latest_update_timestamp <- .get_latest_update_timestamp(self)
.initialize_entities(self, verbose = TRUE)
}
},
#' @description Appends new \code{httr} configs to the existing class.
#' @param ... Configs to pass on to all \code{httr} functions. See \href{https://www.rdocumentation.org/packages/httr/versions/1.4.2/topics/config}{documentation}.
add_httr_configs = function(...) {
self$httr_configs <- c(self$httr_configs, list(...))
},
#' @description Removes all \code{httr} configs from the existing class.
reset_httr_configs = function() {
self$httr_configs <- list()
},
#' @description Retrieves a data frame containing player names, IDs, and other metadata.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ids Player IDs on which to filter. Cannot be combined with \code{names}. Accepts a character vector of length >= 1.
#' @param names Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{ids}. Accepts a character vector of length >= 1.
get_players = function(leagues, ids, names) {
players <- .filter_entity(self, "players", leagues, ids, names)
return(players)
},
#' @description Retrieves a data frame containing team names, abbreviations, and IDs.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ids Team IDs on which to filter. Cannot be combined with \code{names}. Accepts a character vector of length >= 1.
#' @param names Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{ids}. Accepts a character vector of length >= 1.
get_teams = function(leagues, ids, names) {
teams <- .filter_entity(self, "teams", leagues, ids, names)
return(teams)
},
#' @description Retrieves a data frame containing stadium names, IDs, and other metadata.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ids Stadium IDs on which to filter. Cannot be combined with \code{names}. Accepts a character vector of length >= 1.
#' @param names Stadium names on which to filter. Partial matches are accepted. Cannot be combined with \code{ids}. Accepts a character vector of length >= 1.
get_stadia = function(leagues, ids, names) {
stadia <- .filter_entity(self, "stadia", leagues, ids, names)
return(stadia)
},
#' @description Retrieves a data frame containing manager names and IDs.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ids Manager IDs on which to filter. Cannot be combined with \code{names}. Accepts a character vector of length >= 1.
#' @param names Manager names on which to filter. Partial matches are accepted. Cannot be combined with \code{ids}. Accepts a character vector of length >= 1.
get_managers = function(leagues, ids, names) {
managers <- .filter_entity(self, "managers", leagues, ids, names)
return(managers)
},
#' @description Retrieves a data frame containing referee names and IDs.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ids Referee IDs on which to filter. Cannot be combined with \code{names}. Accepts a character vector of length >= 1.
#' @param names Referee names on which to filter. Partial matches are accepted. Cannot be combined with \code{ids}. Accepts a character vector of length >= 1.
get_referees = function(leagues, ids, names) {
referees <- .filter_entity(self, "referees", leagues, ids, names)
return(referees)
},
#' @description Retrieves a data frame containing game IDs, dates, opponents, scores, and other metadata.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param game_ids Game IDs on which to filter. Accepts a character vector of length >= 1.
#' @param team_ids Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' @param team_names Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' @param seasons Name(s)/year(s) of seasons. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' @param stages Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
get_games = function(leagues, game_ids, team_ids, team_names, seasons, stages) {
games <- .get_games(self, leagues, game_ids, team_ids, team_names, seasons, stages)
return(games)
},
#' @description Retrieves a data frame containing player xG data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{minimum_minutes}: Minimum threshold for sum of minutes played.
#' \item \code{minimum_shots}: Minimum threshold for sum of shots taken.
#' \item \code{minimum_key_passes}: Minimum threshold for sum of key passes.
#' \item \code{player_ids}: Player IDs on which to filter. Cannot be combined with \code{player_names}. Accepts a character vector of length >= 1.
#' \item \code{player_names}: Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{player_ids}. Accepts a character vector of length >= 1.
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{shot_pattern}: Describes the possessing actions leading to the shot. Valid keywords include: 'Set piece', 'Corner', 'Free kick', 'Penalty', 'Fastbreak', and 'Regular'. Accepts a character vector of length >= 1.
#' \item \code{split_by_teams}: Logical indicator to group results by team.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{general_position}: Describes the most common position played by each player over the specified period of time. Valid keywords include: 'GK', 'CB', 'FB', 'DM', 'CM', 'AM', 'W', and 'ST'. Accepts a character vector of length >= 1.
#' }
get_player_xgoals = function(leagues, ...) {
player_xgoals <- .get_stats(self, type = "xgoals", entity = "players", leagues, ...)
return(player_xgoals)
},
#' @description Retrieves a data frame containing player xPass data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{minimum_minutes}: Minimum threshold for sum of minutes played.
#' \item \code{minimum_passes}: Minimum threshold for sum of attempted passes.
#' \item \code{player_ids}: Player IDs on which to filter. Cannot be combined with \code{player_names}. Accepts a character vector of length >= 1.
#' \item \code{player_names}: Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{player_ids}. Accepts a character vector of length >= 1.
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{pass_origin_third}: Describes the third of the field from which the pass originated. Valid keywords include: 'Attacking', 'Middle', and 'Defensive'. Accepts a character vector of length >= 1.
#' \item \code{split_by_teams}: Logical indicator to group results by team.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{general_position}: Describes the most common position played by each player over the specified period of time. Valid keywords include: 'GK', 'CB', 'FB', 'DM', 'CM', 'AM', 'W', and 'ST'. Accepts a character vector of length >= 1.
#' }
get_player_xpass = function(leagues, ...) {
player_xpass <- .get_stats(self, type = "xpass", entity = "players", leagues, ...)
return(player_xpass)
},
#' @description Retrieves a data frame containing player goals added (g+) data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{minimum_minutes}: Minimum threshold for sum of minutes played.
#' \item \code{player_ids}: Player IDs on which to filter. Cannot be combined with \code{player_names}. Accepts a character vector of length >= 1.
#' \item \code{player_names}: Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{player_ids}. Accepts a character vector of length >= 1.
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{split_by_teams}: Logical indicator to group results by team.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{action_type}: Describes the goals added (g+) action type. Valid keywords include: 'Dribbling', 'Fouling', 'Interrupting', 'Passing', 'Receiving', and 'Shooting'. Accepts a character vector of length >= 1.
#' \item \code{general_position}: Describes the most common position played by each player over the specified period of time. Valid keywords include: 'GK', 'CB', 'FB', 'DM', 'CM', 'AM', 'W', and 'ST'. Accepts a character vector of length >= 1.
#' \item \code{above_replacement}: Logical indicator to compare players against replacement-level values. This will only return aggregated g+ values, rather than disaggregated g+ values by action type.
#' }
get_player_goals_added = function(leagues, ...) {
player_goals_added <- .get_stats(self, type = "goals-added", entity = "players", leagues, ...)
return(player_goals_added)
},
#' @description Retrieves a data frame containing player salary data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Currently, only MLS salary data is publicly available.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{player_ids}: Player IDs on which to filter. Cannot be combined with \code{player_names}. Accepts a character vector of length >= 1.
#' \item \code{player_names}: Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{player_ids}. Accepts a character vector of length >= 1.
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{position}: Describes the general position, as reported by the players' association. Valid keywords include: 'GK', 'D', 'M', and 'F'. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' }
get_player_salaries = function(leagues, ...) {
player_salaries <- .get_stats(self, type = "salaries", entity = "players", leagues, ...)
return(player_salaries)
},
#' @description Retrieves a data frame containing goalkeeper xG data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{minimum_minutes}: Minimum threshold for sum of minutes played.
#' \item \code{minimum_shots_faced}: Minimum threshold for sum of shots faced.
#' \item \code{player_ids}: Player IDs on which to filter. Cannot be combined with \code{player_names}. Accepts a character vector of length >= 1.
#' \item \code{player_names}: Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{player_ids}. Accepts a character vector of length >= 1.
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{shot_pattern}: Describes the possessing actions leading to the shot. Valid keywords include: 'Set piece', 'Corner', 'Free kick', 'Penalty', 'Fastbreak', and 'Regular'. Accepts a character vector of length >= 1.
#' \item \code{split_by_teams}: Logical indicator to group results by team.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' }
get_goalkeeper_xgoals = function(leagues, ...) {
goalkeeper_xgoals <- .get_stats(self, type = "xgoals", entity = "goalkeepers", leagues, ...)
return(goalkeeper_xgoals)
},
#' @description Retrieves a data frame containing goalkeeper goals added (g+) data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{minimum_minutes}: Minimum threshold for sum of minutes played.
#' \item \code{player_ids}: Player IDs on which to filter. Cannot be combined with \code{player_names}. Accepts a character vector of length >= 1.
#' \item \code{player_names}: Player names on which to filter. Partial matches are accepted. Cannot be combined with \code{player_ids}. Accepts a character vector of length >= 1.
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{split_by_teams}: Logical indicator to group results by team.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{action_type}: Describes the goals added (g+) action type. Valid keywords include: 'Claiming', 'Fielding', 'Handling', 'Passing', 'Shotstopping', and 'Sweeping'. Accepts a character vector of length >= 1.
#' \item \code{above_replacement}: Logical indicator to compare players against replacement-level values. This will only return aggregated g+ values, rather than disaggregated g+ values by action type.
#' }
get_goalkeeper_goals_added = function(leagues, ...) {
goalkeeper_goals_added <- .get_stats(self, type = "goals-added", entity = "goalkeepers", leagues, ...)
return(goalkeeper_goals_added)
},
#' @description Retrieves a data frame containing team xG data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{shot_pattern}: Describes the possessing actions leading to the shot. Valid keywords include: 'Set piece', 'Corner', 'Free kick', 'Penalty', 'Fastbreak', and 'Regular'. Accepts a character vector of length >= 1.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{home_only}: Logical indicator to only include results from home games.
#' \item \code{away_only}: Logical indicator to only include results from away games.
#' \item \code{home_adjusted}: Logical indicator to adjust certain values based on the share of home games a team has played during the specified duration.
#' \item \code{even_game_state}: Logical indicator to only include shots taken when the score was level.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' }
get_team_xgoals = function(leagues, ...) {
team_xgoals <- .get_stats(self, type = "xgoals", entity = "teams", leagues, ...)
return(team_xgoals)
},
#' @description Retrieves a data frame containing team xPass data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{pass_origin_third}: Describes the third of the field from which the pass originated. Valid keywords include: 'Attacking', 'Middle', and 'Defensive'. Accepts a character vector of length >= 1.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{split_by_games}: Logical indicator to group results by game.
#' \item \code{home_only}: Logical indicator to only include results from home games.
#' \item \code{away_only}: Logical indicator to only include results from away games.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' }
get_team_xpass = function(leagues, ...) {
team_xpass <- .get_stats(self, type = "xpass", entity = "teams", leagues, ...)
return(team_xpass)
},
#' @description Retrieves a data frame containing team goals added (g+) data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{split_by_seasons}: Logical indicator to group results by season.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{action_type}: Describes the goals added (g+) action type. Valid keywords include: 'Dribbling', 'Fouling', 'Interrupting', 'Passing', 'Receiving', and 'Shooting'. Accepts a character vector of length >= 1.
#' \item \code{zone}: Zone number on pitch. Zones 1-5 are the defensive-most zones, and zones 26-30 are the attacking-most zones. Accepts a character or integer vector of length >= 1.
#' \item \code{gamestate_trunc}: Integer (score differential) value between -2 and 2, inclusive. Gamestates more extreme than -2 and 2 have been included with -2 and 2, respectively. Accepts a character or integer vector of length >= 1.
#' }
get_team_goals_added = function(leagues, ...) {
team_goals_added <- .get_stats(self, type = "goals-added", entity = "teams", leagues, ...)
return(team_goals_added)
},
#' @description Retrieves a data frame containing team salary data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Currently, only MLS salary data is publicly available.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{team_ids}: Team IDs on which to filter. Cannot be combined with \code{team_names}. Accepts a character vector of length >= 1.
#' \item \code{team_names}: Team names on which to filter. Partial matches and abbreviations are accepted. Cannot be combined with \code{team_ids}. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{split_by_teams}: Logical indicator to group results by team. Results must be grouped by at least one of teams, positions, or seasons. Value is TRUE by default.
#' \item \code{split_by_seasons}: Logical indicator to group results by season. Results must be grouped by at least one of teams, positions, or seasons.
#' \item \code{split_by_positions}: Logical indicator to group results by positions. Results must be grouped by at least one of teams, positions, or seasons.
#' }
get_team_salaries = function(leagues, ...) {
team_salaries <- .get_stats(self, type = "salaries", entity = "teams", leagues, ...)
return(team_salaries)
},
#' @description Retrieves a data frame containing game xG data meeting the specified conditions.
#' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1.
#' @param ... The following arguments will be parsed:
#' \itemize{
#' \item \code{game_ids}: Game IDs on which to filter. Accepts a character vector of length >= 1.
#' \item \code{season_name}: Name(s)/year(s) of seasons. Cannot be combined with a date range. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' \item \code{start_date}: Start of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{end_date}: End of a date range. Must be a string in YYYY-MM-DD format. Cannot be combined with \code{season_name}.
#' \item \code{stage_name}: Describes the stage of competition in which a game took place. See the \href{https://app.americansocceranalysis.com/api/v1/__docs__/}{API documentation} for possible values. Accepts a character vector of length >= 1.
#' }
get_game_xgoals = function(leagues, ...) {
game_xgoals <- .get_stats(self, type = "xgoals", entity = "games", leagues, ...)
return(game_xgoals)
}
)
)