diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index f77f29f5..3d7ed70d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,15 +1,10 @@ +# 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 - schedule: - - cron: 15 15 1,15 * * + branches: [main, master] pull_request: - branches: - - main - - master - - dev + branches: [main, master] workflow_dispatch: name: R-CMD-check @@ -17,7 +12,6 @@ name: R-CMD-check jobs: R-CMD-check: runs-on: ${{ matrix.config.os }} - if: "!contains(github.event.head_commit.message, 'ci skip')" name: ${{ matrix.config.os }} (${{ matrix.config.r }}) @@ -25,46 +19,33 @@ jobs: fail-fast: false 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: macOS-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/all/latest"} - - {os: ubuntu-22.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-22.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} - - {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} + - {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: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} NFLVERSE_GH_TOKEN: ${{ secrets.NFLVERSE_GH_TOKEN }} + R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - 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: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r-dependencies@v2 with: - cache-version: 2 - extra-packages: | - rcmdcheck - ropensci/piggyback - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + extra-packages: any::rcmdcheck, ropensci/piggyback + needs: check - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true diff --git a/NAMESPACE b/NAMESPACE index 482b33cc..a1501945 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(print,nflverse_data) +S3method(print,nflverse_sitrep) export(.clear_cache) export(.for_cran) export(.sitrep) @@ -50,4 +51,5 @@ export(raw_from_url) export(rbindlist_with_attrs) export(rds_from_url) exportClasses(nflverse_data) +exportClasses(nflverse_sitrep) importFrom(data.table,`:=`) diff --git a/NEWS.md b/NEWS.md index 428cc6f3..064478a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,8 @@ etc falsely returned last season after March 15th early in the month. (1.3.2.03) - `nflreadr::nflverse_game_id()` accepts old team abbreviations and outputs useful errors. (1.3.2.05) (#191) - Added `dictionary_player_stats_def` (thank you @mpcen!) (1.3.2.06) (#192) - Added `.for_cran()` to limit parallelization in CRAN examples and tests (1.3.2.07) +- `nflverse_sitrep()` and friends now return a list of sitrep attributes instead of just printing to console. +- `make_nflverse_data_class()` now uses `data.table::setattr()` to set attributes and retain data.table pointer (v1.3.2.08) # nflreadr 1.3.2 diff --git a/R/from_url.R b/R/from_url.R index 0c6d0e2b..47d0c037 100644 --- a/R/from_url.R +++ b/R/from_url.R @@ -243,25 +243,3 @@ loader <- function(url){ detect_filetype <- function(url){ tools::file_ext(gsub(x = url, pattern = ".gz$", replacement = "")) } - -make_nflverse_data <- function(dataframe, nflverse_type = NULL, ...){ - - class(dataframe) <- c("nflverse_data","tbl_df","tbl","data.table","data.frame") - - dots <- rlang::dots_list(..., .named = TRUE) - - for(i in seq_along(dots)){ - attr(dataframe, names(dots)[[i]]) <- dots[[i]] - } - - if(!is.null(nflverse_type)) attr(dataframe, "nflverse_type") <- nflverse_type - - if( - (length(dots) > 0 | !is.null(nflverse_type)) && - is.null(attr(dataframe, "nflverse_timestamp")) - ){ - attr(dataframe, "nflverse_timestamp") <- Sys.time() - } - - return(dataframe) -} diff --git a/R/load_participation.R b/R/load_participation.R index 8be9dbf0..c9323a48 100644 --- a/R/load_participation.R +++ b/R/load_participation.R @@ -52,9 +52,11 @@ load_participation <- function(seasons = most_recent_season(), by.x = c("nflverse_game_id","play_id"), by.y = c("game_id","play_id")) - pbp_participation <- make_nflverse_data(pbp_participation, - nflverse_type = "play-by-play participation", - nflverse_timestamp = attr(participation,"nflverse_timestamp")) + pbp_participation <- make_nflverse_data( + pbp_participation, + nflverse_type = "play-by-play participation", + nflverse_timestamp = attr(participation, "nflverse_timestamp") + ) return(pbp_participation) } diff --git a/R/utils.R b/R/utils.R index 90460b1d..9758e209 100644 --- a/R/utils.R +++ b/R/utils.R @@ -14,22 +14,6 @@ NULL ifelse(!is.na(x),x,y) } -#' @export -#' @noRd -print.nflverse_data <- function(x,...){ - - cli::cli_rule("{.emph nflverse {attr(x,'nflverse_type')}}") - - if(!is.null(attr(x,'nflverse_timestamp'))) { - cli::cli_alert_info( - "Data updated: {.field {format(attr(x,'nflverse_timestamp'), tz = Sys.timezone(), usetz = TRUE)}}" - ) - } - - NextMethod(print,x) - invisible(x) -} - #' rbindlist but maintain attributes of last file #' #' @export @@ -43,16 +27,6 @@ rbindlist_with_attrs <- function(dflist){ out } -#' nflverse data class -#' -#' This class has a special S3 print method that tries to read attached metadata and -#' provide timestamps and source attributes. It otherwise will dispatch to the -#' `data.frame` class. -#' -#' @name nflverse_data-class -#' @exportClass nflverse_data -methods::setOldClass(c("nflverse_data", "data.frame")) - .ignore_unused_imports <- function(){ curl::curl_fetch_memory methods::setOldClass diff --git a/R/utils_nflverse_data_class.R b/R/utils_nflverse_data_class.R new file mode 100644 index 00000000..2e3edd36 --- /dev/null +++ b/R/utils_nflverse_data_class.R @@ -0,0 +1,49 @@ +#' nflverse data class +#' +#' This class has a special S3 print method that tries to read attached metadata and +#' provide timestamps and source attributes. It otherwise will dispatch to the +#' `data.frame` class. +#' +#' @name nflverse_data-class +#' @keywords internal +#' @exportClass nflverse_data +methods::setOldClass(c("nflverse_data", "data.frame")) + +#' @export +#' @noRd +print.nflverse_data <- function(x,...){ + + cli::cli_rule("{.emph nflverse {attr(x,'nflverse_type')}}") + + if(!is.null(attr(x,'nflverse_timestamp'))) { + cli::cli_alert_info( + "Data updated: {.field {format(attr(x,'nflverse_timestamp'), tz = Sys.timezone(), usetz = TRUE)}}" + ) + } + + NextMethod(print,x) + invisible(x) +} + +make_nflverse_data <- function(df, nflverse_type = NULL, ...){ + + df <- data.table::as.data.table(df) + data.table::setattr(df, "class", c("nflverse_data", "tbl_df", "tbl", "data.table","data.frame")) + + dots <- rlang::dots_list(..., .named = TRUE) + + for(i in seq_along(dots)){ + data.table::setattr(df, names(dots)[[i]], dots[[i]]) + } + + if(!is.null(nflverse_type)) data.table::setattr(df, "nflverse_type", nflverse_type) + + if( + (length(dots) > 0 | !is.null(nflverse_type)) && + is.null(attr(df, "nflverse_timestamp")) + ){ + data.table::setattr(df, "nflverse_timestamp", Sys.time()) + } + + return(df) +} diff --git a/R/utils_sitrep.R b/R/utils_sitrep.R index 0cf223e6..458f7e4d 100644 --- a/R/utils_sitrep.R +++ b/R/utils_sitrep.R @@ -32,8 +32,7 @@ #' @export nflverse_sitrep <- function(pkg = c("nflreadr","nflfastR","nflseedR","nfl4th","nflplotR","nflverse"), recursive = TRUE, - redact_path = TRUE - ){ + redact_path = TRUE) { .sitrep(pkg = pkg, recursive = recursive, header = "nflverse ", redact_path = redact_path) } @@ -41,132 +40,215 @@ nflverse_sitrep <- function(pkg = c("nflreadr","nflfastR","nflseedR","nfl4th","n #' @export ffverse_sitrep <- function(pkg = c("ffscrapr","ffsimulator","ffpros","ffopportunity"), recursive = TRUE, - redact_path = TRUE - ){ + redact_path = TRUE) { .sitrep(pkg = pkg, recursive = recursive, header = "ffverse ", redact_path = redact_path) } #' @rdname sitrep #' @export .sitrep <- function(pkg, recursive = TRUE, header = "", redact_path = TRUE){ - packages <- pkg - installed <- unlist(lapply(packages, is_installed)) + out <- structure( + list( + system_info = list(), + installed = list(), + dependencies = list(), + package_options = list(), + not_installed = list(), + packages = pkg, + timestamp = Sys.time() + ), + class = c("nflverse_sitrep", "list") + ) - if (!is.null(pkg)){ - not_installed <- packages[!installed] - if (length(not_installed) >= 1){ - cli::cli_alert_info("You've asked for the package{?s} {not_installed} which {?is/are} not installed. \n {?It/They} {?is/are} skipped.") - } - } + s <- utils::sessionInfo() - packages <- packages[installed] + # OPERATING SYSTEM INFO + out$system_info <- list( + r_version = s$R.version$version.string, + os_version = s$running + ) - if(length(packages) == 0) return(invisible(NULL)) + # PACKAGES FROM LIST + which_installed <- sapply(out$packages, is_installed) + out$not_installed <- out$packages[!which_installed] - s <- utils::sessionInfo(packages) + packages <- out$packages[which_installed] - cli::cat_rule(cli::style_bold("System Info"), col = cli::make_ansi_style("cyan"), line = 1) - cli::cat_bullet(glue::glue("{s$R.version$version.string} {cli::symbol$bullet} Running under: {s$running}")) + if (length(packages) == 0) return(out) - cli::cat_rule(cli::style_bold(paste0(header, "Packages")), col = cli::make_ansi_style("cyan"), line = 1) - packages <- unlist(lapply(s$otherPkgs,function(pkg) pkg$Package)) - versions <- unlist(lapply(s$otherPkgs, function(pkg) pkg$Version)) + s <- utils::sessionInfo(packages) - cat_packages(packages, versions) + out$installed <- lapply(s$otherPkgs, `[`, c("Package", "Version")) + out$installed <- as.data.frame(data.table::rbindlist(out$installed)) + out$installed <- stats::setNames(out$installed, c("package","version")) # Relies on options for a given package being prefixed by said package name opts <- options() - package_opts <- opts[Reduce(lapply(packages, function(package) grepl(package, x = names(opts), fixed = TRUE)),f = `|`)] + pkg_search_string <- paste(packages, collapse = "|") + out$package_options <- opts[grepl(pkg_search_string, x = names(opts))] + if(redact_path) { + out$package_options[grepl("path|token", names(out$package_options))] <- "{redacted, use redact_path = FALSE to show}" + } + + # Exit here if we don't want recursive deps or if no internet + if (isFALSE(recursive)) return(out) + if (!curl::has_internet()) { + cli::cli_alert_warning("Requires internet access to scan recursive dependencies") + return(out) + } + + ## PKG DEPENDENCIES + # using pak allows you to access the dependencies of GitHub-installed packages + # if(is_installed("pak")) out$dependencies <- .sitrep_deps_pak(packages) + out$dependencies <- .sitrep_deps_base(packages) + + return(out) +} - if(redact_path) package_opts[grepl("path", names(package_opts))] <- "{redacted, use redact_path = FALSE to show}" +#' nflverse_sitrep data class +#' +#' `nflverse_sitrep()` returns an S3 class that was created to allow for custom +#' printing. It will otherwise dispatch to the `list` class. +#' +#' Re-exporting with `methods::setOldClass()` allows these dataframes to be used +#' in S4 generics like those from DBI and jsonlite. +#' +#' @name nflverse_sitrep-class +#' @keywords internal +#' @exportClass nflverse_sitrep +methods::setOldClass("nflverse_sitrep", "list") - cli::cat_rule(cli::style_bold(paste0(header, "Options")), col = cli::make_ansi_style("cyan"), line = 1) +#' @export +#' @noRd +print.nflverse_sitrep <- function(x, ...) { + cli::cat_rule(cli::style_bold("System Info"), col = cli::make_ansi_style("cyan"), line = 1) + cli::cat_bullet(glue::glue("{x$system_info$r_version} {cli::symbol$bullet} Running under: {x$system_info$os_version}")) # nolint + + cli::cat_rule(cli::style_bold("Package Status"), col = cli::make_ansi_style("cyan"), line = 1) + .cat_packages(x$installed$package, x$installed$version) - if(length(package_opts) == 0) cli::cli_bullets("No options set for {packages}") - if(length(package_opts) > 0) cat_options(names(package_opts), unname(package_opts)) + cli::cat_rule(cli::style_bold("Package Options"), col = cli::make_ansi_style("cyan"), line = 1) + if (length(x$package_options) == 0) cli::cli_bullets("No options set for above packages") + if (length(x$package_options) > 0) .cat_options(names(x$package_options), unname(x$package_options)) + + if (length(x$dependencies) >= 1) { + cli::cat_rule(cli::style_bold("Package Dependencies"), col = cli::make_ansi_style("cyan"), line = 1) + .cat_packages(x$dependencies$package, x$dependencies$version) + } + if (length(x$not_installed) >= 1) { + cli::cat_rule(cli::style_bold("Not Installed"), col = cli::make_ansi_style("cyan"), line = 1) + .cat_packages(x$not_installed, rep_len("", length(x$not_installed))) + } - # Exit here if we don't want recursive deps - if (isFALSE(recursive)) return(invisible(NULL)) + cli::cat_rule(col = cli::make_ansi_style("cyan"), line = 1) - cli::cat_rule(cli::style_bold(paste0(header, "Dependencies")), col = cli::make_ansi_style("cyan"), line = 1) + return(invisible(x)) +} +# .sitrep_deps_pak <- function(packages){ +# ref <- NULL +# pak_status <- rlang::env_get(rlang::ns_env("pak"), "pkg_status") +# pak_deps <- rlang::env_get(rlang::ns_env("pak"), "pkg_deps") +# pkg_status <- data.table::as.data.table(pak_status(packages)) +# pkg_status <- unique(pkg_status, by = "package") +# pkg_spec <- data.table::fcoalesce(pkg_status$remotepkgref, pkg_status$package) +# +# # Add any repositories found by pkg_status to the search list +# # as well as cran.rstudio.com +# pkg_repos <- unique(c(stats::na.omit(pkg_status$repos), getOption("repos"), "https://cran.rstudio.com")) +# old_repos <- options(repos = pkg_repos) +# on.exit(options(old_repos)) +# +# deps <- data.table::as.data.table(pak_deps(pkg_spec))[!ref %in% pkg_spec][["package"]] +# dep_status <- data.table::as.data.table(pak_status(deps))[,c("package", "version")] +# +# if(any(!deps %in% dep_status$package)) { +# missing_pkgs <- data.table::data.table( +# package = setdiff(deps, dep_status$package), +# version = "missing" +# ) +# data.table::rbindlist(list(dep_status, missing_pkgs)) +# } +# +# return(dep_status) +# } + +.sitrep_deps_base <- function(packages){ # The checks failed because the repo option is empty sometimes # so we set it here to the rstudio mirror and restore the options # after the call to package_dependencies() - old <- options(repos = "https://cran.rstudio.com/") + old <- options(repos = unique(c(getOption("repos"), "https://cran.rstudio.com/"))) + on.exit(options(old)) + deps <- sort( unique( unlist( tools::package_dependencies(packages, recursive = TRUE), - use.names = FALSE) + use.names = FALSE + ) ) ) - # restore old options - options(old) - deps <- deps[!deps %in% packages] sys_pkgs <- utils::installed.packages()[,"Package"] - - if(any(!deps %in% sys_pkgs)){ - missing_pkgs <- deps[!deps %in% sys_pkgs] - rlang::check_installed(missing_pkgs, reason = "in your dependencies.") - } - - s <- utils::sessionInfo(deps) - - packages <- unlist(lapply(s$otherPkgs, function(pkg) pkg$Package)) - versions <- unlist(lapply(s$otherPkgs,function(pkg) pkg$Version)) - - if (is.null(packages)){ - cli::cat_bullet("No non-base dependencies") - return(invisible()) + missing_pkgs <- setdiff(deps, sys_pkgs) + + deps <- intersect(deps, sys_pkgs) + dep_status <- utils::sessionInfo(deps)$otherPkgs + dep_status <- data.table::rbindlist(dep_status, fill = TRUE)[, c("Package", "Version")] + dep_status <- stats::setNames(dep_status, c("package","version")) + if(length(missing_pkgs) > 0) { + dep_status <- data.table::rbindlist( + list( + dep_status, + data.table::data.table(package = missing_pkgs, version = "missing") + ) + ) } - cat_packages(packages,versions) - - cli::cat_rule(col = cli::make_ansi_style("cyan"), line = 1) - + return(dep_status) } -cat_packages <- function(packages,versions){ +.cat_packages <- function(packages, versions) { stopifnot(length(packages) == length(versions)) - if(length(packages) <= 2){ + if (length(packages) <= 2) { cli::cat_bullet(glue::glue("{format(packages)} ({format(versions)})")) return(invisible()) } l <- length(packages) - breaks <- cut(x = seq_along(packages), - breaks = c(0, ceiling(l / 3), 2 * ceiling(l / 3), l+1)) + breaks <- cut( + x = seq_along(packages), + breaks = c(0, ceiling(l / 3), 2 * ceiling(l / 3), l + 1) + ) p <- split(packages, breaks) v <- split(versions, breaks) - r <- length(p[[1]])-length(p[[3]]) + r <- length(p[[1]]) - length(p[[3]]) - if(r != 0){ - p[[3]] <- c(p[[3]],rep("",r)) - v[[3]] <- c(v[[3]],rep("",r)) + if (r != 0) { + p[[3]] <- c(p[[3]], rep("", r)) + v[[3]] <- c(v[[3]], rep("", r)) } - p <- lapply(p, function(x) ifelse(x!="",format(paste(cli::symbol$bullet,x)),"")) - v <- lapply(v, function(x) ifelse(x!="",format(paste0(" (",x,")")),"")) + p <- lapply(p, function(x) ifelse(x != "", format(paste(cli::symbol$bullet, x)), "")) + v <- lapply(v, function(x) ifelse(x != "", format(paste0(" (", x, ")")), "")) cli::cat_line( paste0( - p[[1]],v[[1]]," ", - p[[2]],v[[2]]," ", - p[[3]],v[[3]]," " - )) + p[[1]], v[[1]], " ", + p[[2]], v[[2]], " ", + p[[3]], v[[3]], " " + ) + ) } -cat_options <- function(option_names, option_values){ +.cat_options <- function(option_names, option_values) { stopifnot(length(option_names) == length(option_values)) - cli::cat_bullet(glue::glue("{format(option_names)}: {format(option_values)}")) } diff --git a/man/nflverse_data-class.Rd b/man/nflverse_data-class.Rd index d0419a31..bbe27a0b 100644 --- a/man/nflverse_data-class.Rd +++ b/man/nflverse_data-class.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% Please edit documentation in R/utils_nflverse_data_class.R \name{nflverse_data-class} \alias{nflverse_data-class} \title{nflverse data class} @@ -8,3 +8,4 @@ This class has a special S3 print method that tries to read attached metadata an provide timestamps and source attributes. It otherwise will dispatch to the \code{data.frame} class. } +\keyword{internal} diff --git a/man/nflverse_sitrep-class.Rd b/man/nflverse_sitrep-class.Rd new file mode 100644 index 00000000..ecb536d5 --- /dev/null +++ b/man/nflverse_sitrep-class.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils_sitrep.R +\name{nflverse_sitrep-class} +\alias{nflverse_sitrep-class} +\title{nflverse_sitrep data class} +\description{ +\code{nflverse_sitrep()} returns an S3 class that was created to allow for custom +printing. It will otherwise dispatch to the \code{list} class. +} +\details{ +Re-exporting with \code{methods::setOldClass()} allows these dataframes to be used +in S4 generics like those from DBI and jsonlite. +} +\keyword{internal} diff --git a/tests/testthat/test-from_url.R b/tests/testthat/test-from_url.R index 59e58fdd..d3c1664d 100644 --- a/tests/testthat/test-from_url.R +++ b/tests/testthat/test-from_url.R @@ -7,21 +7,22 @@ test_that("from_url fails nicely", { rds_from_url("https://github.com/nflverse/nfldata/blob/master/data/games.rds"), regexp = "Failed to readRDS" ) + + expect_warning( + raw_from_url("https://github.com/nflverse/nfl/blob/master/data/games.rd"), + regexp = "HTTP error" + ) + + # skip_if(!rlang::is_installed("qs")) expect_warning( qs_from_url("https://github.com/nflverse/nfldata/raw/master/data/games.rds"), regexp = "Failed to parse file" ) - expect_warning( qs_from_url("https://asfdjklasfsadffasd.com"), regexp = "Failed to retrieve data" ) - expect_warning( - raw_from_url("https://github.com/nflverse/nfl/blob/master/data/games.rd"), - regexp = "HTTP error" - ) - }) test_that("progress updates in raw_from_url work", { @@ -67,7 +68,7 @@ test_that("nflverse_download downloads files",{ nflverse_download( "asdf", folder_path = temp_dir, - .token = Sys.getenv("NFLVERSE_GH_TOKEN")), + .token = Sys.getenv("NFLVERSE_GH_TOKEN", unset = gh::gh_token())), "Could not find" ), "No matching releases" @@ -78,7 +79,7 @@ test_that("nflverse_download downloads files",{ combine, "test", folder_path = temp_dir, file_type = "qs", - .token = Sys.getenv("NFLVERSE_GH_TOKEN") + .token = Sys.getenv("NFLVERSE_GH_TOKEN", unset = gh::gh_token()) ), regexp = "Could not find file" ) @@ -87,7 +88,7 @@ test_that("nflverse_download downloads files",{ combine, "contracts", folder_path = temp_dir, file_type = "parquet", - .token = Sys.getenv("NFLVERSE_GH_TOKEN") + .token = Sys.getenv("NFLVERSE_GH_TOKEN", unset = gh::gh_token()) ) expect_true( @@ -101,7 +102,7 @@ test_that("nflverse_releases lists releases",{ skip_on_cran() skip_if_offline("github.com") - releases <- nflverse_releases(.token = Sys.getenv("NFLVERSE_GH_TOKEN")) + releases <- nflverse_releases(.token = Sys.getenv("NFLVERSE_GH_TOKEN", unset = gh::gh_token())) expect_true(is.data.frame(releases)) expect_true(nrow(releases) >= 15) diff --git a/tests/testthat/test-nflverse.R b/tests/testthat/test-nflverse.R index 93ecaecc..d842bb96 100644 --- a/tests/testthat/test-nflverse.R +++ b/tests/testthat/test-nflverse.R @@ -20,7 +20,7 @@ test_that("load_participation", { skip_if_offline("github.com") participation <- load_participation(2019) - pbp_participation <- load_participation(2020,include_pbp = TRUE,file_type = "qs") + pbp_participation <- load_participation(2020,include_pbp = TRUE, file_type = "parquet") expect_s3_class(participation, "nflverse_data") expect_s3_class(pbp_participation, "nflverse_data") @@ -109,7 +109,7 @@ test_that("load_ngs", { skip_if_offline("github.com") ngs_passing <- load_nextgen_stats() - ngs_receiving <- load_nextgen_stats(seasons = 2019:2020, stat_type = "receiving", file_type = "qs") + ngs_receiving <- load_nextgen_stats(seasons = 2019:2020, stat_type = "receiving", file_type = "parquet") ngs_rushing <- load_nextgen_stats(seasons = 2020, stat_type = "rushing") expect_s3_class(ngs_passing, "nflverse_data") diff --git a/tests/testthat/test-utils_sitrep.R b/tests/testthat/test-utils_sitrep.R index 045741f6..6f762a0a 100644 --- a/tests/testthat/test-utils_sitrep.R +++ b/tests/testthat/test-utils_sitrep.R @@ -1,6 +1,20 @@ test_that("sitrep works", { skip_on_cran() - expect_output(.sitrep("nflreadr", recursive = FALSE), regexp = "System Info|R version |Running under|nflreadr \\(") - expect_null(.sitrep("xyz", recursive = FALSE)) - expect_output(nflverse_sitrep(pkg = "nflreadr"), regexp = "System Info|R version |Running under|nflverse Packages|nflreadr \\(|nflverse Dependencies") + nflreadr_sitrep <- .sitrep("nflreadr", recursive = FALSE) + expect_named( + nflreadr_sitrep, + c("system_info", "installed", "dependencies", "package_options", + "not_installed", "packages", "timestamp") + ) + + xyz_sitrep <- .sitrep("xyz", recursive = FALSE) + + expect_true( + all(lengths(xyz_sitrep[c("installed", "dependencies", "package_options")]) == 0) + ) + + expect_output( + print(nflreadr_sitrep), + regexp = "System Info|R version |Running under|Packages|nflreadr \\(" + ) })