Skip to content

Commit

Permalink
Merge pull request #8 from jplecavalier/tidy_games_events
Browse files Browse the repository at this point in the history
Tidy games events
  • Loading branch information
jplecavalier authored Jul 24, 2024
2 parents d8ab2b0 + 7dad807 commit 7aaed36
Show file tree
Hide file tree
Showing 25 changed files with 1,628 additions and 47 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

permissions: read-all

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

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

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

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

steps:
- uses: actions/checkout@v4

- 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: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
66 changes: 34 additions & 32 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

permissions: read-all

jobs:
pkgdown:
runs-on: macOS-latest
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
- uses: actions/checkout@v4

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

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Cache R packages
uses: actions/cache@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
install.packages("pkgdown", type = "binary")
shell: Rscript {0}
extra-packages: any::pkgdown, local::.
needs: website

- name: Install package
run: R CMD INSTALL .
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy package
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

permissions: read-all

jobs:
test-coverage:
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: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- 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_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
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-test-failures
path: ${{ runner.temp }}/package
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ URL: https://jplecavalier.github.io/tidynhl, https://github.com/jplecavalier/tid
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.3.1
Suggests:
testthat,
knitr,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

export(get_players_id)
export(tidy_drafts)
export(tidy_games_events)
export(tidy_games_faceoffs)
export(tidy_games_goals)
export(tidy_goalies_gamelogs)
export(tidy_goalies_stats)
export(tidy_players_meta)
Expand Down
114 changes: 114 additions & 0 deletions R/assert-arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,89 @@ assert_seasons_id <- function(seasons_id) {

}

assert_games_id <- function(games_id, min_season = "19171918") {

if (is.numeric(games_id)) {

games_id <- unique(games_id)

if (all(as.integer(games_id) == games_id, na.rm = TRUE)) {

games_id_na <- which(is.na(games_id))
if (length(games_id_na) > 0L) {
warning("NAs were detected and dropped in the 'games_id' argument")
games_id <- games_id[-games_id_na]
}

if (!exists("seasons_meta", envir = data)) {
load_seasons_meta()
}
seasons_meta <- get("seasons_meta", envir = data)

missing_games <- games_id[which(nchar(games_id) != 10L)]
games_id <- setdiff(games_id, missing_games)

missing_games <- unique(c(
missing_games,
games_id[which(!(substr(games_id, 1L, 4L) %in% seasons_meta[, substr(season_id, 1L, 4L)]))],
games_id[which(!(substr(games_id, 5L, 6L) %in% c("02", "03")))]
))
games_id <- setdiff(games_id, missing_games)

seasons_id <- unique(substr(games_id, 1L, 4L))
seasons_id <- paste0(seasons_id, as.character(as.integer(seasons_id) + 1L))

schedules <- tidy_schedules(
seasons_id = seasons_id,
expand_periods = FALSE,
regular = TRUE,
playoffs = TRUE,
tz = Sys.timezone(),
keep_id = TRUE,
return_datatable = TRUE
)

missing_games <- c(missing_games, schedules[, setdiff(games_id, game_id)])
games_id <- setdiff(games_id, missing_games)
if (length(missing_games) > 0L) {
warning(paste(
"the following elements of the argument 'games_id' were dropped since not identified",
"as valid NHL game IDs:",
paste(sort(missing_games), collapse = ", ")
))
}

unavailable_games <- schedules[as.integer(season_id) >= as.integer(min_season),
setdiff(games_id, game_id)]
games_id <- setdiff(games_id, unavailable_games)
if (length(unavailable_games) > 0L) {
warning(paste(
"the following elements of the argument 'games_id' were dropped since this particular",
"data is unavailable for those games:",
paste(sort(unavailable_games), collapse = ", ")
))
}

incomplete_games <- schedules[game_status == "final", setdiff(games_id, game_id)]
games_id <- setdiff(games_id, incomplete_games)
if (length(incomplete_games) > 0L) {
warning(paste(
"the following elements of the argument 'games_id' were dropped since those games are",
"not completed yet:",
paste(sort(incomplete_games), collapse = ", ")
))
}

return(as.integer(games_id))

}

}

stop("argument 'games_id' should be a vector of integers")

}

assert_players_id <- function(players_id) {

if (is.numeric(players_id)) {
Expand Down Expand Up @@ -217,6 +300,37 @@ assert_tz <- function(tz) {

}

assert_include_shootout <- function(include_shootout) {

if (is.logical(include_shootout) & !anyNA(include_shootout) & length(include_shootout) == 1L) {
return(NULL)
}

stop("argument 'include_shootout' should be one of 'TRUE' or 'FALSE'")

}

assert_time_elapsed <- function(time_elapsed) {

if (is.logical(time_elapsed) & !anyNA(time_elapsed) & length(time_elapsed) == 1L) {
return(NULL)
}

stop("argument 'time_elapsed' should be one of 'TRUE' or 'FALSE'")

}

assert_standardized_coordinates <- function(standardized_coordinates) {

if (is.logical(standardized_coordinates) & !anyNA(standardized_coordinates) &
length(standardized_coordinates) == 1L) {
return(NULL)
}

stop("argument 'standardized_coordinates' should be one of 'TRUE' or 'FALSE'")

}

assert_keep_id <- function(keep_id) {

if (is.logical(keep_id) & !anyNA(keep_id) & length(keep_id) == 1L) {
Expand Down
Loading

0 comments on commit 7aaed36

Please sign in to comment.