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
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
Expand All @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 8 additions & 12 deletions R/gt_nfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions R/nflplotR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions man/gt_nfl_cols_label.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gt_nfl_headshots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/gt_nfl_logos.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-nfl_team_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down