diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index fe216507..896e7750 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -26,7 +26,7 @@ jobs: matrix: config: - {os: windows-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/all/latest"} - - {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"} + #- {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"} - {os: macOS-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/all/latest"} - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} diff --git a/DESCRIPTION b/DESCRIPTION index 952a2f01..729b385c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: nflreadr Title: Download 'nflverse' Data -Version: 1.3.1.07 +Version: 1.3.2 Authors@R: c( person("Tan", "Ho", , "tan@tanho.ca", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0001-8388-5155")), diff --git a/NEWS.md b/NEWS.md index 4235ccd9..9c22496d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,14 +1,18 @@ -# nflreadr (development version) +# nflreadr 1.3.2 + +Minor changes per changelist and patch CRAN-related example issue. ## Changes -- `.clear_cache()` now re-exported without dot prefix as `clear_cache()`. Hopefully more obvious. (v1.3.1.01) -- `join_coalesce()` is now added as a utility to join two dataframes and coalesce any shared columns. (v1.3.1.02) +- `.clear_cache()` now re-exported without dot prefix as `clear_cache()`. Hopefully more obvious. +- `join_coalesce()` is now added as a utility to join two dataframes and coalesce any shared columns. - `load_teams()` now uses the argument `current` (TRUE/FALSE) to standardize which rows are returned - this aligns with `nflreadr::clean_team_abbrs` and `nflreadr::team_abbr_mapping` -- `dictionary_participation` added (thank you @josephhero!) (v1.3.1.04) -- `clean_homeaway()` now preserves neutral site location as well as input class and input attributes (v1.3.1.05) -- `load_ff_rankings()` URL bug corrected (thank you @kharigardner) (v1.3.1.06) -- test for `clean_homeaway()` resolved for CRAN failure (v1.3.1.07) +- `dictionary_participation` added (thank you @josephhero!) +- `clean_homeaway()` now preserves neutral site location as well as input class and input attributes +- `load_ff_rankings()` URL bug corrected (thank you @kharigardner) +- test and example for `clean_homeaway()` resolved for CRAN failure + +Thank you to [@ak47twq](https://github.com/ak47twq), [@bachlaw](https://github.com/bachlaw), [@brunomioto](https://github.com/brunomioto), [@guga31bb](https://github.com/guga31bb), [@Josephhero](https://github.com/Josephhero), [@kharigardner](https://github.com/kharigardner), [@mrcaseb](https://github.com/mrcaseb), [@MysteryPollster](https://github.com/MysteryPollster), [@numbersinfigures](https://github.com/numbersinfigures), and [@ohri](https://github.com/ohri) for their questions, feedback, and contributions towards this release. --- @@ -32,7 +36,7 @@ Fixes CRAN bug and provides some function improvements, most notably improved lo - player name mapping update - `get_current_season()` now exists, because we can't agree on what to name things. -Thank you to [@atungate](https://github.com/atungate),[@grayhawk40](https://github.com/grayhawk40), [@guga31bb](https://github.com/guga31bb),[@jestarr](https://github.com/jestarr), [@john-b-edwards](https://github.com/john-b-edwards),[@marvin3FF](https://github.com/marvin3FF),[@mrcaseb](https://github.com/mrcaseb), [@SCasanova](https://github.com/SCasanova), [@shirondru](https://github.com/shirondru), [@tanho63](https://github.com/tanho63), and [@TheMathNinja](https://github.com/TheMathNinja) for their contributions and feedback towards this release! +Thank you to [@atungate](https://github.com/atungate), @grayhawk40, [@guga31bb](https://github.com/guga31bb),[@jestarr](https://github.com/jestarr), [@john-b-edwards](https://github.com/john-b-edwards),[@marvin3FF](https://github.com/marvin3FF),[@mrcaseb](https://github.com/mrcaseb), [@SCasanova](https://github.com/SCasanova), [@shirondru](https://github.com/shirondru), [@tanho63](https://github.com/tanho63), and [@TheMathNinja](https://github.com/TheMathNinja) for their contributions and feedback towards this release! --- diff --git a/R/utils_join_coalesce.R b/R/utils_join_coalesce.R index fea03ff4..9f5de07e 100644 --- a/R/utils_join_coalesce.R +++ b/R/utils_join_coalesce.R @@ -48,6 +48,19 @@ join_coalesce <- function(x, y, by = NULL, keys_x <- if (!is.null(by.x)) by.x else if(is.null(names(by))) by else ifelse(names(by) == "", by, names(by)) keys_y <- if (!is.null(by.y)) by.y else by + check_keys <- c( + "Join `by` keys in x are not unique" = nrow(x) != nrow(unique(x[keys_x])), + "Join `by` keys in y are not unique" = nrow(y) != nrow(unique(y[keys_y])), + "Join `by` keys in x have NAs" = any(is.na(x[keys_x])), + "Join `by` keys in y have NAs"= any(is.na(y[keys_y])) + ) + + if(any(check_keys)) { + cli::cli_warn( + names(check_keys)[which(check_keys)] + ) + } + joined_cols <- c(setdiff(names(x), keys_x), setdiff(names(y), keys_y)) dupl_cols <- joined_cols[duplicated(joined_cols)] diff --git a/README.Rmd b/README.Rmd index 85bb25b6..04565c6f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -25,7 +25,7 @@ options(tibble.max_extra_cols = 10, [![Codecov test coverage](https://img.shields.io/codecov/c/github/nflverse/nflreadr?label=codecov&style=flat-square&logo=codecov)](https://app.codecov.io/gh/nflverse/nflreadr?branch=main) [![Dev status](https://img.shields.io/github/r-package/v/nflverse/nflreadr/main?label=dev%20version&style=flat-square&logo=github)](https://nflreadr.nflverse.com/) [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg?style=flat-square)](https://lifecycle.r-lib.org/articles/stages.html) -[![R build status](https://img.shields.io/github/workflow/status/nflverse/nflreadr/R-CMD-check?label=R%20check&style=flat-square&logo=github)](https://github.com/nflverse/nflreadr/actions) +[![R build status](https://img.shields.io/github/actions/workflow/status/nflverse/nflreadr/R-CMD-check.yaml?label=R%20check&style=flat-square&logo=github)](https://github.com/nflverse/nflreadr/actions) [![nflverse discord](https://img.shields.io/discord/789805604076126219?color=7289da&label=nflverse%20discord&logo=discord&logoColor=fff&style=flat-square)](https://discord.com/invite/5Er2FBnnQa) diff --git a/README.md b/README.md index 92718f7d..1221de47 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ status](https://img.shields.io/github/r-package/v/nflverse/nflreadr/main?label=d [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg?style=flat-square)](https://lifecycle.r-lib.org/articles/stages.html) [![R build -status](https://img.shields.io/github/workflow/status/nflverse/nflreadr/R-CMD-check?label=R%20check&style=flat-square&logo=github)](https://github.com/nflverse/nflreadr/actions) +status](https://img.shields.io/github/actions/workflow/status/nflverse/nflreadr/R-CMD-check.yaml?label=R%20check&style=flat-square&logo=github)](https://github.com/nflverse/nflreadr/actions) [![nflverse discord](https://img.shields.io/discord/789805604076126219?color=7289da&label=nflverse%20discord&logo=discord&logoColor=fff&style=flat-square)](https://discord.com/invite/5Er2FBnnQa) @@ -45,7 +45,7 @@ install.packages("nflreadr") Install the development version from GitHub with: ``` r -install.packages("nflreadr", repos = c("https://nflverse.r-universe.dev",getOption("repos"))) +install.packages("nflreadr", repos = c("https://nflverse.r-universe.dev", getOption("repos"))) # or use remotes/devtools # install.packages("remotes") @@ -60,46 +60,52 @@ The main functions of `nflreadr` are prefixed with `load_`. library(nflreadr) load_pbp(2021) -#> ── nflverse play by play ─────────────────────────────────────────────────────── -#> ℹ Data updated: 2022-07-28 18:10:55 EDT +#> ── nflverse play by play data ────────────────────────────────────────────────── +#> ℹ Data updated: 2022-09-27 07:35:02 EDT #> # A tibble: 50,712 × 372 -#> play_id game_id old_game_id home_team away_team season_type week posteam -#> -#> 1 1 2021_01_AR… 2021091207 TEN ARI REG 1 -#> 2 40 2021_01_AR… 2021091207 TEN ARI REG 1 TEN -#> 3 55 2021_01_AR… 2021091207 TEN ARI REG 1 TEN -#> 4 76 2021_01_AR… 2021091207 TEN ARI REG 1 TEN -#> 5 100 2021_01_AR… 2021091207 TEN ARI REG 1 TEN -#> 6 122 2021_01_AR… 2021091207 TEN ARI REG 1 TEN -#> 7 152 2021_01_AR… 2021091207 TEN ARI REG 1 ARI -#> 8 181 2021_01_AR… 2021091207 TEN ARI REG 1 ARI -#> 9 218 2021_01_AR… 2021091207 TEN ARI REG 1 ARI -#> 10 253 2021_01_AR… 2021091207 TEN ARI REG 1 ARI -#> # … with 50,702 more rows, and 364 more variables: posteam_type , -#> # defteam , side_of_field , yardline_100 , game_date , -#> # quarter_seconds_remaining , half_seconds_remaining , -#> # game_seconds_remaining , game_half , quarter_end , … +#> play_id game_id old_g…¹ home_…² away_…³ seaso…⁴ week posteam poste…⁵ defteam +#> +#> 1 1 2021_0… 202109… TEN ARI REG 1 +#> 2 40 2021_0… 202109… TEN ARI REG 1 TEN home ARI +#> 3 55 2021_0… 202109… TEN ARI REG 1 TEN home ARI +#> 4 76 2021_0… 202109… TEN ARI REG 1 TEN home ARI +#> 5 100 2021_0… 202109… TEN ARI REG 1 TEN home ARI +#> 6 122 2021_0… 202109… TEN ARI REG 1 TEN home ARI +#> 7 152 2021_0… 202109… TEN ARI REG 1 ARI away TEN +#> 8 181 2021_0… 202109… TEN ARI REG 1 ARI away TEN +#> 9 218 2021_0… 202109… TEN ARI REG 1 ARI away TEN +#> 10 253 2021_0… 202109… TEN ARI REG 1 ARI away TEN +#> # … with 50,702 more rows, 362 more variables: side_of_field , +#> # yardline_100 , game_date , quarter_seconds_remaining , +#> # half_seconds_remaining , game_seconds_remaining , +#> # game_half , quarter_end , drive , sp , …, and +#> # abbreviated variable names ¹​old_game_id, ²​home_team, ³​away_team, +#> # ⁴​season_type, ⁵​posteam_type +#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names load_player_stats(2021) #> ── nflverse player stats: offense ────────────────────────────────────────────── -#> ℹ Data updated: 2022-07-28 18:18:44 EDT -#> # A tibble: 5,698 × 48 -#> player_id player_name recent_team season week season_type completions -#> -#> 1 00-0019596 T.Brady TB 2021 1 REG 32 -#> 2 00-0019596 T.Brady TB 2021 2 REG 24 -#> 3 00-0019596 T.Brady TB 2021 3 REG 41 -#> 4 00-0019596 T.Brady TB 2021 4 REG 22 -#> 5 00-0019596 T.Brady TB 2021 5 REG 30 -#> 6 00-0019596 T.Brady TB 2021 6 REG 34 -#> 7 00-0019596 T.Brady TB 2021 7 REG 20 -#> 8 00-0019596 T.Brady TB 2021 8 REG 28 -#> 9 00-0019596 T.Brady TB 2021 10 REG 23 -#> 10 00-0019596 T.Brady TB 2021 11 REG 30 -#> # … with 5,688 more rows, and 41 more variables: attempts , +#> ℹ Data updated: 2023-01-05 04:08:21 EST +#> # A tibble: 5,698 × 52 +#> player…¹ playe…² playe…³ posit…⁴ posit…⁵ heads…⁶ recen…⁷ season week seaso…⁸ +#> +#> 1 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 1 REG +#> 2 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 2 REG +#> 3 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 3 REG +#> 4 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 4 REG +#> 5 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 5 REG +#> 6 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 6 REG +#> 7 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 7 REG +#> 8 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 8 REG +#> 9 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 10 REG +#> 10 00-0019… T.Brady Tom Br… QB QB https:… TB 2021 11 REG +#> # … with 5,688 more rows, 42 more variables: completions , attempts , #> # passing_yards , passing_tds , interceptions , sacks , #> # sack_yards , sack_fumbles , sack_fumbles_lost , -#> # passing_air_yards , passing_yards_after_catch , … +#> # passing_air_yards , …, and abbreviated variable names ¹​player_id, +#> # ²​player_name, ³​player_display_name, ⁴​position, ⁵​position_group, +#> # ⁶​headshot_url, ⁷​recent_team, ⁸​season_type +#> # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names ``` ## Data Sources @@ -107,11 +113,11 @@ load_player_stats(2021) Data accessed by this package is stored on GitHub and can typically be found in one of the following repositories: -- [nflverse/nflverse-data](https://github.com/nflverse/nflverse-data) -- [nflverse/nfldata](https://github.com/nflverse/nfldata) -- [nflverse/espnscrapeR-data](https://github.com/nflverse/espnscrapeR-data) -- [dynastyprocess/data](https://github.com/dynastyprocess/data) -- [ffverse/ffopportunity](https://github.com/ffverse/ffopportunity) +- [nflverse/nflverse-data](https://github.com/nflverse/nflverse-data) +- [nflverse/nfldata](https://github.com/nflverse/nfldata) +- [nflverse/espnscrapeR-data](https://github.com/nflverse/espnscrapeR-data) +- [dynastyprocess/data](https://github.com/dynastyprocess/data) +- [ffverse/ffopportunity](https://github.com/ffverse/ffopportunity) For a full list of functions, please see the [reference page](https://nflreadr.nflverse.com/reference/index.html). @@ -147,22 +153,22 @@ progressr::with_progress(load_rosters(seasons = 2010:2020)) The best places to get help on this package are: -- the [nflverse discord](https://discord.com/invite/5Er2FBnnQa) (for - both this package as well as anything R/NFL related) -- opening [an - issue](https://github.com/nflverse/nflreadr/issues/new/choose) +- the [nflverse discord](https://discord.com/invite/5Er2FBnnQa) (for + both this package as well as anything R/NFL related) +- opening [an + issue](https://github.com/nflverse/nflreadr/issues/new/choose) ## Contributing Many hands make light work! Here are some ways you can contribute to this project: -- You can [open an - issue](https://github.com/nflverse/nflreadr/issues/new/choose) if - you’d like to request specific data or report a bug/error. +- You can [open an + issue](https://github.com/nflverse/nflreadr/issues/new/choose) if + you’d like to request specific data or report a bug/error. -- If you’d like to contribute code, please check out [the contribution - guidelines](https://nflreadr.nflverse.com/CONTRIBUTING.html). +- If you’d like to contribute code, please check out [the contribution + guidelines](https://nflreadr.nflverse.com/CONTRIBUTING.html). ## Terms of Use diff --git a/man/clean_homeaway.Rd b/man/clean_homeaway.Rd index 3de1b533..f51e9c6e 100644 --- a/man/clean_homeaway.Rd +++ b/man/clean_homeaway.Rd @@ -20,18 +20,17 @@ This function converts dataframes with "home_" and "away_" prefixed columns to " \examples{ \donttest{ # a small example dataframe - - s <- data.frame( - game_id = c("2020_20_TB_GB", "2020_20_BUF_KC", "2020_21_KC_TB"), - game_type = c("CON", "CON", "SB"), - away_team = c("TB", "BUF", "KC"), - away_score = c(31L, 24L, 9L), - home_team = c("GB", "KC", "TB"), - home_score = c(26L, 38L, 31L), - location = c("Home", "Home", "Neutral"), - result = c(-5L, 14L, 22L), - spread_line = c(3, 3, -3) - ) +s <- data.frame( + game_id = c("2020_20_TB_GB", "2020_20_BUF_KC", "2020_21_KC_TB"), + game_type = c("CON", "CON", "SB"), + away_team = c("TB", "BUF", "KC"), + away_score = c(31L, 24L, 9L), + home_team = c("GB", "KC", "TB"), + home_score = c(26L, 38L, 31L), + location = c("Home", "Home", "Neutral"), + result = c(-5L, 14L, 22L), + spread_line = c(3, 3, -3) + ) clean_homeaway(s, invert = c("result","spread_line")) } diff --git a/tests/testthat/test-utils_date.R b/tests/testthat/test-utils_date.R index a85c5afc..e8e087f5 100644 --- a/tests/testthat/test-utils_date.R +++ b/tests/testthat/test-utils_date.R @@ -1,7 +1,10 @@ test_that("latest week methods are equivalent", { + + skip_if(packageVersion('nflreadr') == '1.3.2', + "Skip date check for v1.3.2 because of 2022 Bengals/Bills game problems.") + skip_on_cran() skip_if_offline("github.com") - # This test fails during the season on Tuesdays and Wednesdays # Blame Tan and Ben smh skip_if(as.POSIXlt(Sys.Date())$wday %in% 2:3) diff --git a/vignettes/exporting_nflreadr.Rmd b/vignettes/exporting_nflreadr.Rmd index d3122c7b..f467a15f 100644 --- a/vignettes/exporting_nflreadr.Rmd +++ b/vignettes/exporting_nflreadr.Rmd @@ -32,8 +32,10 @@ load_rosters <- function(seasons = 1999:2020){ # Form the URLs to pass into rds_from_url urls <- paste0( - "https://github.com/nflverse/nflverse-rosters/raw/master/data/seasons/roster_", - seasons, ".rds") + "https://github.com/nflverse/nflverse-rosters/", + "raw/master/data/seasons/roster_", + seasons, + ".rds") # Use `progressively()` to wrap the existing function rds_from_url and # call the `p()` progressor function as a signal immediately after each iteration