8
8
# ' @importFrom dplyr filter select rename bind_cols bind_rows
9
9
# ' @importFrom tidyr unnest unnest_wider everything
10
10
# ' @export
11
- # '
12
11
# ' @examples
13
- # '
14
- # ' espn_wbb_game_all(game_id = 401276115)
15
- # '
12
+ # ' espn_wbb_game_all(game_id = 401276115)
16
13
17
14
espn_wbb_game_all <- function (game_id ,verbose = FALSE ){
18
15
options(stringsAsFactors = FALSE )
@@ -108,6 +105,15 @@ espn_wbb_game_all <- function(game_id, verbose = FALSE){
108
105
109
106
player_box <- dplyr :: bind_cols(stats_df ,players_df ) %> %
110
107
dplyr :: select(.data $ athlete.displayName ,.data $ team.shortDisplayName ,tidyr :: everything())
108
+ plays_df <- plays_df %> %
109
+ janitor :: clean_names()
110
+ team_box_score <- team_box_score %> %
111
+ janitor :: clean_names()
112
+ player_box <- player_box %> %
113
+ janitor :: clean_names() %> %
114
+ dplyr :: rename(
115
+ fg3 = .data $ x3pt
116
+ )
111
117
},
112
118
error = function (e ) {
113
119
if (verbose ){
@@ -135,11 +141,8 @@ espn_wbb_game_all <- function(game_id, verbose = FALSE){
135
141
# ' @importFrom dplyr filter select rename bind_cols bind_rows
136
142
# ' @importFrom tidyr unnest unnest_wider everything
137
143
# ' @export
138
- # '
139
144
# ' @examples
140
- # '
141
- # ' espn_wbb_pbp(game_id = 401276115)
142
- # '
145
+ # ' espn_wbb_pbp(game_id = 401276115)
143
146
espn_wbb_pbp <- function (game_id ,verbose = FALSE ){
144
147
options(stringsAsFactors = FALSE )
145
148
options(scipen = 999 )
@@ -167,6 +170,8 @@ espn_wbb_pbp <- function(game_id, verbose = FALSE){
167
170
names(aths )[1 ]<- c(" play.id" )
168
171
plays_df <- dplyr :: bind_cols(plays ,aths ) %> %
169
172
select(- .data $ athlete.id )
173
+ plays_df <- plays_df %> %
174
+ janitor :: clean_names()
170
175
},
171
176
error = function (e ) {
172
177
if (verbose ){
@@ -191,12 +196,8 @@ espn_wbb_pbp <- function(game_id, verbose = FALSE){
191
196
# ' @importFrom dplyr filter select rename bind_cols bind_rows
192
197
# ' @importFrom tidyr unnest unnest_wider everything
193
198
# ' @export
194
- # '
195
199
# ' @examples
196
- # '
197
- # '
198
200
# ' espn_wbb_team_box(game_id = 401276115)
199
- # '
200
201
espn_wbb_team_box <- function (game_id ,verbose = FALSE ){
201
202
options(stringsAsFactors = FALSE )
202
203
options(scipen = 999 )
@@ -223,6 +224,8 @@ espn_wbb_team_box <- function(game_id, verbose = FALSE){
223
224
tm <- c(teams_box_score_df [2 ," team.shortDisplayName" ]," Team" ,teams_box_score_df [1 ," team.shortDisplayName" ])
224
225
names(tm )<- c(" Home" ," label" ," Away" )
225
226
team_box_score = dplyr :: bind_rows(tm ,team_box_score )
227
+ team_box_score <- team_box_score %> %
228
+ janitor :: clean_names()
226
229
},
227
230
error = function (e ) {
228
231
if (verbose ) message(glue :: glue(" {Sys.time()}: Invalid arguments or no team box score data for {game_id} available!" ))
@@ -245,11 +248,8 @@ espn_wbb_team_box <- function(game_id, verbose = FALSE){
245
248
# ' @importFrom dplyr filter select rename bind_cols bind_rows
246
249
# ' @importFrom tidyr unnest unnest_wider everything
247
250
# ' @export
248
- # '
249
251
# ' @examples
250
- # '
251
252
# ' espn_wbb_player_box(game_id = 401276115)
252
- # '
253
253
espn_wbb_player_box <- function (game_id ,verbose = FALSE ){
254
254
options(stringsAsFactors = FALSE )
255
255
options(scipen = 999 )
@@ -286,6 +286,11 @@ espn_wbb_player_box <- function(game_id, verbose = FALSE){
286
286
287
287
player_box <- dplyr :: bind_cols(stats_df ,players_df ) %> %
288
288
dplyr :: select(.data $ athlete.displayName ,.data $ team.shortDisplayName ,tidyr :: everything())
289
+ player_box <- player_box %> %
290
+ janitor :: clean_names() %> %
291
+ dplyr :: rename(
292
+ fg3 = .data $ x3pt
293
+ )
289
294
},
290
295
error = function (e ) {
291
296
if (verbose ) message(glue :: glue(" {Sys.time()}: Invalid arguments or no player box score data for {game_id} available!" ))
@@ -313,9 +318,7 @@ espn_wbb_player_box <- function(game_id, verbose = FALSE){
313
318
# ' @export
314
319
# '
315
320
# ' @examples
316
- # '
317
321
# ' espn_wbb_teams()
318
- # '
319
322
320
323
espn_wbb_teams <- function (){
321
324
options(stringsAsFactors = FALSE )
@@ -352,8 +355,24 @@ espn_wbb_teams <- function(){
352
355
stats <- s %> % unnest_wider(.data $ g )
353
356
354
357
records <- dplyr :: bind_cols(records %> %dplyr :: select(.data $ summary ),stats )
355
- leagues <- leagues %> %dplyr :: select(- .data $ record ,- .data $ links )
356
- teams <- dplyr :: bind_cols(leagues ,records )
358
+ leagues <- leagues %> %dplyr :: select(
359
+ - .data $ record ,
360
+ - .data $ links ,
361
+ - .data $ isActive ,
362
+ - .data $ isAllStar ,
363
+ - .data $ uid ,
364
+ - .data $ slug )
365
+ teams <- leagues %> %
366
+ dplyr :: rename(
367
+ logo = .data $ logos_href_1 ,
368
+ logo_dark = .data $ logos_href_2 ,
369
+ mascot = .data $ name ,
370
+ team = .data $ location ,
371
+ team_id = .data $ id ,
372
+ short_name = .data $ shortDisplayName ,
373
+ alternate_color = .data $ alternateColor ,
374
+ display_name = .data $ displayName
375
+ )
357
376
},
358
377
error = function (e ) {
359
378
message(glue :: glue(" {Sys.time()}: Invalid arguments or no teams data available!" ))
@@ -382,7 +401,6 @@ espn_wbb_teams <- function(){
382
401
# ' @export
383
402
# ' @examples
384
403
# ' # Get schedule returns 1000 results, max allowable.
385
- # ' # Must iterate through dates to get full year's schedule, as below:
386
404
# ' # Get schedule from date 2021-02-15, then next date and so on.
387
405
# ' espn_wbb_scoreboard (season = "20210215")
388
406
@@ -485,12 +503,15 @@ espn_wbb_scoreboard <- function(season, verbose = FALSE){
485
503
broadcast_market = list (1 ," market" ),
486
504
broadcast_name = list (1 ," names" ,1 )
487
505
) %> %
488
- dplyr :: select(! where(is.list ))
506
+ dplyr :: select(! where(is.list )) %> %
507
+ janitor :: clean_names()
489
508
}else {
490
- schedule_out
509
+ schedule_out %> %
510
+ janitor :: clean_names()
491
511
}
492
512
}else {
493
- wbb_data %> %dplyr :: select(! where(is.list ))
513
+ wbb_data %> %dplyr :: select(! where(is.list )) %> %
514
+ janitor :: clean_names()
494
515
}
495
516
},
496
517
error = function (e ) {
@@ -528,7 +549,8 @@ ncaa_wbb_NET_rankings <- function(){
528
549
xml2 :: read_html() %> %
529
550
rvest :: html_nodes(" table" ))[[1 ]] %> %
530
551
rvest :: html_table(fill = TRUE ) %> %
531
- dplyr :: as_tibble()
552
+ dplyr :: as_tibble() %> %
553
+ janitor :: clean_names()
532
554
},
533
555
error = function (e ) {
534
556
message(glue :: glue(" {Sys.time()}: Invalid arguments or no NET rankings available!" ))
@@ -584,7 +606,8 @@ espn_wbb_rankings <- function(){
584
606
)
585
607
ranks <- ranks %> %
586
608
dplyr :: select(- dplyr :: any_of(drop_cols ))
587
- ranks <- ranks %> %dplyr :: arrange(.data $ name ,- .data $ points )
609
+ ranks <- ranks %> %dplyr :: arrange(.data $ name ,- .data $ points ) %> %
610
+ janitor :: clean_names()
588
611
return (ranks )
589
612
}
590
613