From 1cd6ef34bcc92e47e5ffd5d8167a695dc88679ef Mon Sep 17 00:00:00 2001 From: Philip Bulsink Date: Wed, 19 Jul 2023 20:10:39 -0400 Subject: [PATCH 1/2] Add sprint_date to output of `load_schedule()` #132 --- R/load_schedule.R | 27 ++++++++++++++++++++++++++- tests/testthat/test-load_schedule.R | 5 +++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/R/load_schedule.R b/R/load_schedule.R index aee89f4a..7ac39a85 100644 --- a/R/load_schedule.R +++ b/R/load_schedule.R @@ -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() %>% @@ -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() } diff --git a/tests/testthat/test-load_schedule.R b/tests/testthat/test-load_schedule.R index 96dab21e..fa247b53 100644 --- a/tests/testthat/test-load_schedule.R +++ b/tests/testthat/test-load_schedule.R @@ -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) }) From 7814d76431793e0c3882cbee2aab534dffcf343f Mon Sep 17 00:00:00 2001 From: Philip Bulsink Date: Wed, 19 Jul 2023 20:12:39 -0400 Subject: [PATCH 2/2] version bump to 1.2.1 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0d9de358..e2edafaa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index e1956b6e..4f1c6289 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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.