Skip to content

Commit

Permalink
Add constructor_id to sprint results
Browse files Browse the repository at this point in the history
Wrapping up SCasanova#37
  • Loading branch information
pbulsink committed Jun 20, 2023
1 parent cbe52c9 commit 7e23ea9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions R/load_sprint.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#' @importFrom magrittr "%>%"
#' @importFrom rlang .data
#' @keywords internal
#' @return A dataframetibble with columns driver_id, points awarded, finishing position,
#' @return A dataframetibble with columns driver_id, constructor_id, points awarded, finishing position,
#' grid position, laps completed, race status (finished or otherwise), gap to
#' first place, fastest lap, fastest lap time, fastest lap in seconds,
#' or NULL if no sprint exists for this season/round combo

.load_sprint <- function(season = 'current', round = 'last'){
if(season != 'current' & (season < 2021 | season > get_current_season())){
stop(glue::glue('Year must be between 1950 and {current} (or use "current")',
stop(glue::glue('Year must be between 2021 and {current} (or use "current")',
current = get_current_season()))
}

Expand All @@ -30,24 +30,27 @@
return(NULL)
}

data$MRData$RaceTable$Races$SprintResults[[1]] %>%
tidyr::unnest(cols = c("Driver", "Time", "FastestLap"),
data<- data$MRData$RaceTable$Races$SprintResults[[1]]

data %>%
tidyr::unnest(cols = c("Driver", "Constructor", "Time", "FastestLap"),
names_repair = 'universal') %>%
tidyr::unnest(cols = c("Time"),
names_repair = 'universal') %>%
suppressWarnings() %>%
suppressMessages() %>%
dplyr::select(
"driverId",
"constructorId",
"points",
"position",
"grid",
"laps",
"status",
"position",
gap = "time...18",
gap = "time...21",
"lap",
fastest = "time...20"
fastest = "time...23"
) %>%
dplyr::mutate(time_sec = time_to_sec(.data$fastest)) %>%
tibble::as_tibble() %>%
Expand All @@ -63,7 +66,7 @@
#' @param season number from 2021 to current season (defaults to current season).
#' @param round number from 1 to 23 (depending on season), and defaults
#' to most recent.
#' @return A tibble with columns driver_id, points awarded, finishing position,
#' @return A tibble with columns driver_id, constructor_id, points awarded, finishing position,
#' grid position, laps completed, race status (finished or otherwise), gap to
#' first place, fastest lap, fastest lap time, fastest lap in seconds,
#' or NULL if no sprint exists for this season/round combo
Expand Down
2 changes: 1 addition & 1 deletion man/dot-load_sprint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/load_sprint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e23ea9

Please sign in to comment.