Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 10 additions & 78 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ jobs:
extra-packages: any::rcmdcheck
needs: check

- name: setup r-reticulate venv
shell: Rscript {0}
run: |
python_packages <- c("numpy", "fastf1")

library(reticulate)
virtualenv_create("r-reticulate", Sys.which("python"))
virtualenv_install("r-reticulate", python_packages)

path_to_python <- virtualenv_python("r-reticulate")
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
Expand Down Expand Up @@ -107,58 +94,6 @@ jobs:
with:
upload-snapshots: true

R-CMD-check-old-ff1:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }}) old fastf1

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: actions/setup-python@v4
with:
python-version: "3.x"

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- name: setup r-reticulate venv
shell: Rscript {0}
run: |
python_packages <- c("urllib3", "fastf1==3.3.9")

library(reticulate)
virtualenv_create("r-reticulate", Sys.which("python"))
virtualenv_install("r-reticulate", python_packages)

path_to_python <- virtualenv_python("r-reticulate")
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true

R-CMD-check-hard:
# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends,
# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never
Expand Down Expand Up @@ -201,6 +136,7 @@ jobs:
any::knitr
any::rmarkdown
any::markdown
any::vcr
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down Expand Up @@ -245,19 +181,15 @@ jobs:
- name: setup r-reticulate venv
shell: Rscript {0}
run: |
python_packages <- c("numpy")

library(reticulate)
virtualenv_create("r-reticulate", Sys.which("python"))
virtualenv_install("r-reticulate", python_packages)
#force dev version install with repl python from reticulate
repl_python(quiet = TRUE)
%pip install git+https://github.com/theOehrly/Fast-F1.git
exit

path_to_python <- virtualenv_python("r-reticulate")
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))
path_to_python <- reticulate::virtualenv_create(
envname = "r-reticulate",
python = Sys.which("python"),
packages = c("numpy")
)
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))
reticulate::py_require('fastf1@git+https://github.com/theOehrly/Fast-F1.git')
reticulate::py_available(TRUE)

- uses: r-lib/actions/check-r-package@v2
with:
Expand Down
87 changes: 1 addition & 86 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ jobs:
any::xml2
needs: coverage

- name: setup r-reticulate venv
shell: Rscript {0}
run: |
python_packages <- c("numpy", "fastf1")

library(reticulate)
virtualenv_create("r-reticulate", Sys.which("python"))
virtualenv_install("r-reticulate", python_packages)

path_to_python <- virtualenv_python("r-reticulate")
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))

- name: Test coverage
run: |
cov <- covr::package_coverage(
Expand Down Expand Up @@ -81,79 +68,6 @@ jobs:
name: coverage-test-failures
path: ${{ runner.temp }}/package

test-coverage-oldff1:
name: Test coverage - old fastf1

runs-on: ubuntu-latest

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: actions/setup-python@v4
with:
python-version: "3.x"

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::covr
any::devtools
any::xml2
needs: coverage

- name: setup r-reticulate venv
shell: Rscript {0}
run: |
python_packages <- c("urllib3", "fastf1==3.3.9")

library(reticulate)
virtualenv_create("r-reticulate", Sys.which("python"))
virtualenv_install("r-reticulate", python_packages)

path_to_python <- virtualenv_python("r-reticulate")
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
Sys.getenv("GITHUB_ENV"))

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-oldff1-test-failures
path: ${{ runner.temp }}/package

test-coverage-hard:
# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends,
# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never
Expand Down Expand Up @@ -194,6 +108,7 @@ jobs:
any::covr
any::devtools
any::xml2
any::vcr
needs: coverage

- name: Test coverage
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Depends:
R (>= 3.5.0),
reticulate (>= 1.14),
reticulate (>= 1.41)
Imports:
glue,
magrittr,
Expand All @@ -42,6 +42,7 @@ Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
vcr
VignetteBuilder: knitr
URL: https://scasanova.github.io/f1dataR/, https://github.com/SCasanova/f1dataR
BugReports: https://github.com/SCasanova/f1dataR/issues
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export(load_session_laps)
export(load_sprint)
export(load_standings)
export(plot_fastest)
export(setup_fastf1)
export(theme_dark_f1)
import(reticulate)
importFrom(magrittr,"%>%")
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# f1dataR (development version)

* Updated code to match new `reticulate` interface for package and environment management.
* Updated tests to use `vcr` package to reduce hits on the Jolpica API
* Removed support for FastF1 v < 3.0 (now causes errors instead of warnings).
* Test suite and automated testing changes to reflect the above changes.
* Fixed a data conversion issue in `time_to_sec()` (#290)

# f1dataR 2.0.1
Expand Down
2 changes: 1 addition & 1 deletion R/load_circuits.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load_circuits <- function(season = get_current_season()) {
cli::cli_abort('{.var season} must be between 1950 and {get_current_season()} (or use "current")')
}

url <- glue::glue("{season}/circuits.json?limit=40",
url <- glue::glue("{season}/circuits.json",
season = season
)

Expand Down
11 changes: 5 additions & 6 deletions R/load_constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#' @return A tibble with one row per constructor
load_constructors <- function() {
lim <- 100
url <- glue::glue("constructors.json?limit={lim}", lim = lim)
data <- get_jolpica_content(url)
url <- "constructors.json"
parameters <- list(limit = lim)
data <- get_jolpica_content(url, parameters)

if (is.null(data)) {
return(NULL)
Expand All @@ -24,10 +25,8 @@ load_constructors <- function() {
while (offset + lim <= total) {
offset <- offset + lim

url <- glue::glue("constructors.json?limit={lim}&offset={offset}",
lim = lim, offset = offset
)
data <- get_jolpica_content(url)
parameters <- list(limit = lim, offset = offset)
data <- get_jolpica_content(url, parameters)

if (is.null(data)) {
return(NULL)
Expand Down
2 changes: 1 addition & 1 deletion R/load_driver_telemetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ load_driver_telemetry <- function(season = get_current_season(), round = 1, sess
driver = driver
))
} else if (laps != "all") {
reticulate::py_run_string(glue::glue("tel = session.laps.pick_drivers('{driver}').pick_lap({laps}).get_telemetry().add_distance().add_driver_ahead()",
reticulate::py_run_string(glue::glue("tel = session.laps.pick_drivers('{driver}').pick_laps({laps}).get_telemetry().add_distance().add_driver_ahead()",
driver = driver, laps = laps
))
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/load_drivers.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load_drivers <- function(season = get_current_season()) {
cli::cli_abort('{.var season} must be between 1950 and {get_current_season()} (or use "current")')
}

url <- glue::glue("{season}/drivers.json?limit=50",
url <- glue::glue("{season}/drivers.json",
season = season
)
data <- get_jolpica_content(url)
Expand Down
11 changes: 4 additions & 7 deletions R/load_laps.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ load_laps <- function(season = get_current_season(), round = "last", race = life
lim <- 100

# Function Code
url <- glue::glue("{season}/{round}/laps.json?limit={lim}",
season = season, round = round, lim = lim
url <- glue::glue("{season}/{round}/laps.json",
season = season, round = round
)
data <- get_jolpica_content(url)
data <- get_jolpica_content(url, parameters = list("limit" = lim))

if (is.null(data)) {
return(NULL)
Expand All @@ -43,10 +43,7 @@ load_laps <- function(season = get_current_season(), round = "last", race = life
while (offset + lim <= total) {
offset <- offset + lim

url <- glue::glue("{season}/{round}/laps.json?limit={lim}&offset={offset}",
lim = lim, season = season, round = round, offset = offset
)
data <- get_jolpica_content(url)
data <- get_jolpica_content(url, parameters = list(limit = lim, offset = offset))

if (is.null(data)) {
return(NULL)
Expand Down
4 changes: 2 additions & 2 deletions R/load_pitstops.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ load_pitstops <- function(season = get_current_season(), round = "last", race =
}

# Function Code
url <- glue::glue("{season}/{round}/pitstops.json?limit=100",
url <- glue::glue("{season}/{round}/pitstops.json",
season = season, round = round
)
data <- get_jolpica_content(url)
data <- get_jolpica_content(url, parameters = list(limit = 100))

if (is.null(data)) {
return(NULL)
Expand Down
2 changes: 1 addition & 1 deletion R/load_quali.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ load_quali <- function(season = get_current_season(), round = "last") {
cli::cli_abort('{.var season} must be between 2003 and {get_current_season()} (or use "current")')
}

url <- glue::glue("{season}/{round}/qualifying.json?limit=40",
url <- glue::glue("{season}/{round}/qualifying.json",
season = season, round = round
)

Expand Down
2 changes: 1 addition & 1 deletion R/load_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load_results <- function(season = get_current_season(), round = "last") {
}

url <- glue::glue(
"{season}/{round}/results.json?limit=40",
"{season}/{round}/results.json",
season = season,
round = round
)
Expand Down
2 changes: 1 addition & 1 deletion R/load_schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ load_schedule <- function(season = get_current_season()) {
cli::cli_abort('{.var season} must be between 1950 and {get_current_season()} (or use "current")')
}

url <- glue::glue("{season}.json?limit=30", season = season)
url <- glue::glue("{season}.json", season = season)

data <- get_jolpica_content(url)
if (is.null(data)) {
Expand Down
4 changes: 2 additions & 2 deletions R/load_sprint.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
load_sprint <- function(season = get_current_season(), round = "last") {
if (season != "current" && (season < 2021 || season > get_current_season())) {
cli::cli_abort(
'{.var season} must be between 2021 and {get_current_season()} (or use "current")'
'{.var season} must be between 2021 and {get_current_season()} (or use "current").'
)
}

url <- glue::glue(
"{season}/{round}/sprint.json?limit=40",
"{season}/{round}/sprint.json",
season = season,
round = round
)
Expand Down
Loading