diff --git a/DESCRIPTION b/DESCRIPTION index ff01c38..8c1714a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: nflplotR Title: NFL Logo Plots in 'ggplot2' and 'gt' -Version: 1.4.0.9002 +Version: 1.4.0.9003 Authors@R: person("Sebastian", "Carl", , "mrcaseb@gmail.com", role = c("aut", "cre")) Description: A set of functions to visualize National Football League @@ -9,9 +9,8 @@ License: MIT + file LICENSE URL: https://nflplotr.nflverse.com, https://github.com/nflverse/nflplotR BugReports: https://github.com/nflverse/nflplotR/issues Depends: - R (>= 3.5.0) + R (>= 4.1.0) Imports: - backports (>= 1.1.6), cachem (>= 1.0.0), cli (>= 3.0.0), data.table (>= 1.14.0), @@ -34,7 +33,7 @@ Suggests: rsvg (>= 2.0), testthat (>= 3.0.0), vdiffr (>= 1.0.2), - webshot2 (>= 0.1.0) + webshot2 (>= 0.1.1) Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 065f343..dbf9275 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,18 +32,12 @@ export(scale_color_nfl) export(scale_colour_nfl) export(scale_fill_nfl) export(valid_team_names) -if (getRversion() >= "4.0.0") { - importFrom(tools, R_user_dir) -} else { - importFrom(backports, R_user_dir) -} import(data.table) import(grid) importFrom(ggplot2,element_grob) importFrom(graphics,par) -importFrom(gt,"%>%") importFrom(lifecycle,deprecated) importFrom(nflreadr,nflverse_sitrep) importFrom(rlang,"%||%") importFrom(rlang,.data) -importFrom(utils,capture.output) +importFrom(tools,R_user_dir) diff --git a/NEWS.md b/NEWS.md index 70d6e18..bf868aa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * The theme elements `element_nfl_logo()` and `element_nfl_wordmark()` now clean team abbreviations by calling `nflreadr::clean_team_abbrs()` and insert empty grobs for mismatches. * All geoms and theme elements will print more informative warnings about team abbreviation, or player ID mismatches. * The gt logo rendering functions now add alt text for accessibility and to silence an annoying pkgdown warning. (#69) +* nflplotR now requires R 4.1 because magick needs this R version. This also follows the [Tidyverse R version support rules](https://www.tidyverse.org/blog/2019/04/r-version-support/). (#71) # nflplotR 1.4.0 diff --git a/R/gt_nfl.R b/R/gt_nfl.R index d010e87..7713ab4 100644 --- a/R/gt_nfl.R +++ b/R/gt_nfl.R @@ -38,9 +38,9 @@ #' wordmark_b = tail(teams, 16) #' ) #' # create gt table and translate team names to logo/wordmark images -#' table <- df %>% -#' gt() %>% -#' gt_nfl_logos(columns = gt::starts_with("logo")) %>% +#' table <- df |> +#' gt() |> +#' gt_nfl_logos(columns = gt::starts_with("logo")) |> #' gt_nfl_wordmarks(columns = gt::starts_with("wordmark")) #' } gt_nfl_logos <- function(gt_object, @@ -104,12 +104,12 @@ gt_nfl_wordmarks <- function(gt_object, #' #' # create gt table and translate player IDs and team abbreviations #' # into headshots, logos, and wordmarks -#' table <- gt::gt(label_df) %>% +#' table <- gt::gt(label_df) |> #' nflplotR::gt_nfl_cols_label( #' columns = gt::starts_with("00"), #' type = "headshot" -#' ) %>% -#' nflplotR::gt_nfl_cols_label("LAC", type = "wordmark") %>% +#' ) |> +#' nflplotR::gt_nfl_cols_label("LAC", type = "wordmark") |> #' nflplotR::gt_nfl_cols_label("KC", type = "logo") #' } gt_nfl_cols_label <- function(gt_object, @@ -269,7 +269,7 @@ get_image_uri <- function(team_abbr, type = c("logo", "wordmark")) { #' ) #' #' # Replace player IDs with headshot images -#' table <- gt(df) %>% +#' table <- gt(df) |> #' gt_nfl_headshots("player_gsis") #' #' # Restore old options @@ -341,11 +341,7 @@ gt_render_image <- function(gt_tbl, ...){ temp_file <- tempfile(fileext = ".png") # webshot2 sends a message that can't be suppressed with suppressMessages() # so we capture the output and return it invisibly - output <- gt::gtsave(gt_tbl, temp_file, ...) %>% - utils::capture.output(type = "message") %>% - invisible() - # if the output is something other than the annoying webshot message, print it - if(!grepl("screenshot completed", output)) print(output) + output <- gt::gtsave(gt_tbl, temp_file, quiet = TRUE, ...) # get rid of the file when function exits on.exit(unlink(temp_file)) # remove margin from plots so we render the table only diff --git a/R/nflplotR-package.R b/R/nflplotR-package.R index 81d80a8..df7d0a7 100644 --- a/R/nflplotR-package.R +++ b/R/nflplotR-package.R @@ -9,13 +9,7 @@ #' @importFrom ggplot2 element_grob #' @importFrom graphics par #' @importFrom lifecycle deprecated -#' @importFrom gt %>% #' @importFrom rlang .data %||% -#' @importFrom utils capture.output -#' @rawNamespace if (getRversion() >= "4.0.0") { -#' importFrom(tools, R_user_dir) -#' } else { -#' importFrom(backports, R_user_dir) -#' } +#' @importFrom tools R_user_dir ## usethis namespace: end NULL diff --git a/R/zzz.R b/R/zzz.R index 6679702..472237d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -6,7 +6,6 @@ if(!memoise_option %in% c("memory", "filesystem", "off")) memoise_option <- "memory" if(memoise_option == "filesystem"){ - backports::import(pkgname, "R_user_dir") cache_dir <- R_user_dir("nflplotR", "cache") if (!dir.exists(cache_dir)) dir.create(cache_dir, recursive = TRUE, showWarnings = FALSE) cache <- cachem::cache_disk(dir = cache_dir) diff --git a/man/gt_nfl_cols_label.Rd b/man/gt_nfl_cols_label.Rd index 9012ca6..bc0cab1 100644 --- a/man/gt_nfl_cols_label.Rd +++ b/man/gt_nfl_cols_label.Rd @@ -51,12 +51,12 @@ label_df <- data.frame( # create gt table and translate player IDs and team abbreviations # into headshots, logos, and wordmarks -table <- gt::gt(label_df) \%>\% +table <- gt::gt(label_df) |> nflplotR::gt_nfl_cols_label( columns = gt::starts_with("00"), type = "headshot" - ) \%>\% - nflplotR::gt_nfl_cols_label("LAC", type = "wordmark") \%>\% + ) |> + nflplotR::gt_nfl_cols_label("LAC", type = "wordmark") |> nflplotR::gt_nfl_cols_label("KC", type = "logo") } } diff --git a/man/gt_nfl_headshots.Rd b/man/gt_nfl_headshots.Rd index 0141577..2350b87 100644 --- a/man/gt_nfl_headshots.Rd +++ b/man/gt_nfl_headshots.Rd @@ -62,7 +62,7 @@ df <- data.frame( ) # Replace player IDs with headshot images -table <- gt(df) \%>\% +table <- gt(df) |> gt_nfl_headshots("player_gsis") # Restore old options diff --git a/man/gt_nfl_logos.Rd b/man/gt_nfl_logos.Rd index 40e3d93..be03438 100644 --- a/man/gt_nfl_logos.Rd +++ b/man/gt_nfl_logos.Rd @@ -54,9 +54,9 @@ df <- data.frame( wordmark_b = tail(teams, 16) ) # create gt table and translate team names to logo/wordmark images -table <- df \%>\% - gt() \%>\% - gt_nfl_logos(columns = gt::starts_with("logo")) \%>\% +table <- df |> + gt() |> + gt_nfl_logos(columns = gt::starts_with("logo")) |> gt_nfl_wordmarks(columns = gt::starts_with("wordmark")) } } diff --git a/tests/testthat/test-nfl_team_factors.R b/tests/testthat/test-nfl_team_factors.R index 2f49850..dbc506f 100644 --- a/tests/testthat/test-nfl_team_factors.R +++ b/tests/testthat/test-nfl_team_factors.R @@ -13,7 +13,7 @@ test_that("nfl team factors work", { plot_data <- mpg # add a new column by randomly sampling the above defined teams vector - plot_data$team <- sample(teams, nrow(mpg), replace = TRUE) %>% + plot_data$team <- sample(teams, nrow(mpg), replace = TRUE) |> nfl_team_factor(rev(team_abbr)) # Now we plot the data and facet by team abbreviation. ggplot automatically @@ -26,7 +26,7 @@ test_that("nfl team factors work", { # We'll change the order of facets by making another team name column and # converting it to an ordered factor. Again, this defaults to sort by division # and nick name in ascending order. - plot_data$ordered_team <- sample(teams, nrow(mpg), replace = TRUE) %>% + plot_data$ordered_team <- sample(teams, nrow(mpg), replace = TRUE) |> nfl_team_factor() # Let's check how the facets are ordered now.