Skip to content

Commit

Permalink
Merge pull request #133 from pbulsink/schedule-sprint
Browse files Browse the repository at this point in the history
load_schedule shows Sprint Race date
  • Loading branch information
SCasanova authored Jul 20, 2023
2 parents 696559a + 7814d76 commit c9dfbdd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: f1dataR
Title: F1 Data in R
Version: 1.2.0
Version: 1.2.1
Authors@R:
c(person(given = "Santiago",
family = "Casanova",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# f1dataR 1.2.1

* Added additional output column to `load_schedule()` to show Sprint Race date.

# f1dataR 1.2.0

* Added a helper function for setting up `fastf1` connection.
Expand Down
27 changes: 26 additions & 1 deletion R/load_schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
"lat":"country",
"date"
) %>%
dplyr::mutate("time" = NA_character_, "sprint_date" = NA_character_) %>%
tibble::as_tibble() %>%
janitor::clean_names()
} else {
} else if (season < 2021) {
data$MRData$RaceTable$Races %>%
tidyr::unnest(cols = c("Circuit"), names_repair = "universal") %>%
janitor::clean_names() %>%
Expand All @@ -50,6 +51,30 @@
"date",
"time"
) %>%
dplyr::mutate("sprint_date" = NA_character_) %>%
tibble::as_tibble() %>%
janitor::clean_names()
} else {
data$MRData$RaceTable$Races %>%
tidyr::unnest(cols = c("Circuit"), names_repair = "universal") %>%
janitor::clean_names() %>%
suppressWarnings() %>%
suppressMessages() %>%
tidyr::unnest(cols = c("location", "sprint"), names_sep = "_") %>%
dplyr::select(
"season",
"round",
"race_name",
"circuit_id",
"circuit_name",
"lat" = "location_lat",
"long" = "location_long",
"locality" = "location_locality",
"country" = "location_country",
"date",
"time",
"sprint_date"
) %>%
tibble::as_tibble() %>%
janitor::clean_names()
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-load_schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ test_that("Schedule Load works", {
expect_equal(schedule_1999$circuit_id[1], "albert_park")

expect_error(load_schedule(3050), "`season` must be between 1950 and *")

schedule_2018 <- load_schedule(2018)
expect_true(all(is.na(schedule_1999$sprint_date)))
expect_true(all(is.na(schedule_2018$sprint_date)))
expect_equal(sum(!is.na(schedule_2021$sprint_date)), 3)
})

0 comments on commit c9dfbdd

Please sign in to comment.