Skip to content

Commit

Permalink
Variable selector can now handle missing columns
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Apr 28, 2020
1 parent cd1cc34 commit 4e2c8ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: nflfastR
Title: Functions to Efficiently Scrape NFL Play by Play and
Roster Data
Version: 1.0.2
Version: 1.0.3
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down
21 changes: 16 additions & 5 deletions R/helper_variable_selector.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@

select_variables <- function(pbp) {
if (!"game_key" %in% colnames(pbp)) {
cols <- c(nflscrapr_cols, new_cols)
out <-
pbp %>%
dplyr::select(
tidyselect::any_of(
c(nflscrapr_cols, new_cols)
)
)
} else {
cols <- c(nflscrapr_cols, new_cols, rs_cols)
out <-
pbp %>%
dplyr::select(
tidyselect::any_of(
c(nflscrapr_cols, new_cols, rs_cols)
)
)
}

pbp <- pbp[cols]

return(pbp)
return(out)
}

# columns that are not in gamecenter that we created
Expand Down Expand Up @@ -111,3 +121,4 @@ rs_cols <- c(
"alert_play_type", "play_type_nfl", "time_of_day",
"yards", "end_yardline_side", "end_yardline_number"
)

0 comments on commit 4e2c8ee

Please sign in to comment.