diff --git a/R/clear_f1_cache.R b/R/clear_f1_cache.R index a904e58f..24b4b890 100644 --- a/R/clear_f1_cache.R +++ b/R/clear_f1_cache.R @@ -18,7 +18,7 @@ clear_f1_cache <- function() { if (reticulate::py_available(initialize = TRUE)) { if ("fastf1" %in% reticulate::py_list_packages()$package) { reticulate::py_run_string("import fastf1") - if (get_fastf1_version() >= 3) { + if (get_fastf1_version()$major >= 3) { try( reticulate::py_run_string(glue::glue("fastf1.Cache.clear_cache('{cache_dir}')", cache_dir = normalizePath(getOption("f1dataR.cache")) diff --git a/R/load_driver_telemetry.R b/R/load_driver_telemetry.R index 26a0bf5d..c89b456c 100644 --- a/R/load_driver_telemetry.R +++ b/R/load_driver_telemetry.R @@ -56,7 +56,7 @@ load_driver_telemetry <- function(season = get_current_season(), round = 1, sess # Param checks if (!(laps %in% c("fastest", "all"))) { if (is.numeric(laps)) { - if (get_fastf1_version() < 3) { + if (get_fastf1_version()$major < 3) { cli::cli_abort("{.var laps} can only be a lap number if using fastf1 v3.0 or higher") } if (as.numeric(laps) != as.integer(laps)) { @@ -80,7 +80,7 @@ load_driver_telemetry <- function(season = get_current_season(), round = 1, sess } ) - if (get_fastf1_version() < 3) { + if (get_fastf1_version()$major < 3) { add_v3_option <- "" } else { add_v3_option <- ".add_driver_ahead()" diff --git a/R/load_race_session.R b/R/load_race_session.R index 604baaeb..bba52062 100644 --- a/R/load_race_session.R +++ b/R/load_race_session.R @@ -69,7 +69,7 @@ load_race_session <- function(obj_name = "session", season = get_current_season( } reticulate::py_run_string("import fastf1") - if (get_fastf1_version() >= 3) { + if (get_fastf1_version()$major >= 3) { reticulate::py_run_string(glue::glue("fastf1.set_log_level('{log_level}')", log_level = log_level)) } diff --git a/R/load_session_laps.R b/R/load_session_laps.R index 5c00bf06..a7e771b5 100644 --- a/R/load_session_laps.R +++ b/R/load_session_laps.R @@ -32,7 +32,7 @@ load_session_laps <- function(season = get_current_season(), round = 1, session round <- race } - if (get_fastf1_version() < 3) { + if (get_fastf1_version()$major < 3) { cli::cli_alert_warning("An old version of FastF1 is in use. Additional data is provided if using FastF1 v3.0.0 or later.") } @@ -60,7 +60,7 @@ load_session_laps <- function(season = get_current_season(), round = 1, session )) } - if (session == "Q" && get_fastf1_version() >= 3) { + if (session == "Q" && get_fastf1_version()$major >= 3) { # prepping for Q1/Q2/Q3 labels - this has to happen before timedelta64 is converted to seconds reticulate::py_run_string(paste("q1, q2, q3 = laps.split_qualifying_sessions()", "q1len = len(q1.index)", @@ -91,7 +91,7 @@ load_session_laps <- function(season = get_current_season(), round = 1, session laps <- laps %>% dplyr::mutate("Time" = .data$Time) - if (session == "Q" && get_fastf1_version() >= 3) { + if (session == "Q" && get_fastf1_version()$major >= 3) { # pull the lengths of each Quali session from the python env. q1len <- reticulate::py_to_r(reticulate::py_get_item(py_env, "q1len")) q2len <- reticulate::py_to_r(reticulate::py_get_item(py_env, "q2len")) diff --git a/R/utils.R b/R/utils.R index 980d77c1..102e609f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -120,14 +120,16 @@ get_fastf1_version <- function() { cli::cli_warn("Ensure {.pkg fastf1} Python package is installed.\nPlease run this to install the most recent version:\n{.code setup_fastf1()}") return(NA) } - if (as.integer(substr(ver, start = 1, 1)) >= 3) { - return(3) - } else if (as.integer(substr(ver, start = 1, 1)) <= 2) { + major <- as.integer(unlist(strsplit(ver, ".", fixed = T))[1]) + minor <- as.integer(unlist(strsplit(ver, ".", fixed = T))[2]) + if (major < 3 | (major == 3 & minor < 1)) { + lifecycle::deprecate_warn("1.4.1", + what = I("fastf1 version < 3.1"), with = I("fastf1 version >= 3.1"), + details = c("Hard deprecation will occur between 2023 and 2024 F1 seasons") + ) cli::cli_inform("The Python package {.pgk fastf1} was updated to v3 recently.\nPlease update the version on your system by running:\n{.code setup_fastf1(newenv = TRUE)}\nFuture versions of {.pkg f1dataR} may not support {.pkg fastf1<3.0.0}.") - return(2) - } else { - return(NA) } + return(list(major = major, minor = minor)) } # nocov start diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 00000000..8c20a4b0 Binary files /dev/null and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-load_driver_telemetry.R b/tests/testthat/test-load_driver_telemetry.R index e4cedd55..c2b4e21e 100644 --- a/tests/testthat/test-load_driver_telemetry.R +++ b/tests/testthat/test-load_driver_telemetry.R @@ -18,7 +18,7 @@ test_that("driver telemetry", { expect_true(nrow(telem) > nrow(telem_fast)) expect_true(ncol(telem) == ncol(telem_fast)) - if (get_fastf1_version() >= 3) { + if (get_fastf1_version()$major >= 3) { expect_equal(telem_fast$session_time[[1]], 3518.641) expect_equal(telem_fast$time[[2]], 0.086) } # else { @@ -30,7 +30,7 @@ test_that("driver telemetry", { # "can only be a lap number if using fastf1 v3.0 or higher" # ) # } - if (get_fastf1_version() >= 3) { + if (get_fastf1_version()$major >= 3) { telem_lap <- load_driver_telemetry(season = 2022, round = "Brazil", session = "S", driver = "HAM", laps = 1) expect_equal(telem_lap$time[[1]], 0) expect_equal(telem_lap$speed[[1]], 0) diff --git a/tests/testthat/test-load_session_laps.R b/tests/testthat/test-load_session_laps.R index 39b2f8a9..3141f9c1 100644 --- a/tests/testthat/test-load_session_laps.R +++ b/tests/testthat/test-load_session_laps.R @@ -23,7 +23,7 @@ test_that("load session laps works", { expect_equal(laps$time, laps2$time) expect_true(!is.na(laps$time[1])) expect_equal(nrow(laps), nrow(laps2)) - if (get_fastf1_version() >= 3) { + if (get_fastf1_version()$major >= 3) { expect_true(all(lapsq$session_type %in% c("Q1", "Q2", "Q3"))) expect_true(all(c("Q1", "Q2", "Q3") %in% unique(lapsq$session_type))) } diff --git a/vignettes/setup_fastf1.Rmd b/vignettes/setup_fastf1.Rmd index 9f1fa00a..047dc2dc 100644 --- a/vignettes/setup_fastf1.Rmd +++ b/vignettes/setup_fastf1.Rmd @@ -21,7 +21,7 @@ the Python package [`FastF1`](https://docs.fastf1.dev/). This guide may help res that might arise when you get the following warning or error messages: - `Ensure fastf1 python package is installed. Please run this to install the most recent version: setup_fastf1()` -- `Error in if (get_fastf1_version() < 3) { :` +- `Error in if (get_fastf1_version()$major < 3) { :` `missing value where TRUE/FALSE needed` If these happen to you (particularly if you're a new user of `f1dataR`) read on!