diff --git a/DESCRIPTION b/DESCRIPTION index 607615c..8ddf1fb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Imports: nflreadr (>= 1.1.2), purrr (>= 0.3.0), rappdirs (>= 0.3.0), + recipes (>= 0.1.16), rlang (>= 0.1.0), stats, stringr (>= 1.4.0), diff --git a/NAMESPACE b/NAMESPACE index 6de4921..5e12187 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,7 @@ # Generated by roxygen2: do not edit by hand -S3method(print,ffep_download) -S3method(print,ffep_output) +S3method(print,ffopps_build) +S3method(print,ffopps_load) export("%>%") export(.get_rosters) export(ep_build) @@ -10,6 +10,7 @@ export(ep_load) export(ep_predict) export(ep_preprocess) export(ep_summarize) +import(recipes) import(xgboost) importFrom(magrittr,"%>%") importFrom(rlang,.data) diff --git a/R/ep_build.R b/R/ep_build.R index 7f25b59..0e0b8a5 100644 --- a/R/ep_build.R +++ b/R/ep_build.R @@ -55,14 +55,14 @@ ep_build <- function(season = nflreadr:::most_recent_season(), version = "latest ep_version = version, timestamp = Sys.time() ), - class = "ffep_output" + class = "ffopps_build" ) return(out) } #' @export #' @noRd -print.ffep_output <- function(x, ...) { +print.ffopps_build <- function(x, ...) { cli::cli_alert("") cli::cli_alert("Generated {x$timestamp} with model version {x$ep_version}") utils::str(x, max.level = 2, give.attr = FALSE) diff --git a/R/ep_load.R b/R/ep_load.R index cac579e..65b9506 100644 --- a/R/ep_load.R +++ b/R/ep_load.R @@ -45,7 +45,7 @@ ep_load <- function(season = nflreadr:::most_recent_season(), rawToChar() %>% as.POSIXct() - class(out) <- c("ffep_download","tbl_df", "tbl", "data.frame") + class(out) <- c("ffopps_load","tbl_df", "tbl", "data.frame") attr(out, "ep_version") <- version attr(out, "ep_timestamp") <- ts attr(out, "ep_type") <- type @@ -54,7 +54,7 @@ ep_load <- function(season = nflreadr:::most_recent_season(), #' @export #' @noRd -print.ffep_download <- function(x, ...) { +print.ffopps_load <- function(x, ...) { cli::cli_alert("") cli::cli_alert("Generated {.val {attr(x,'ep_timestamp')}} with ep model version {.val {attr(x,'ep_version')}}") NextMethod(print,x) diff --git a/R/ep_predict.R b/R/ep_predict.R index 871b371..18b6221 100644 --- a/R/ep_predict.R +++ b/R/ep_predict.R @@ -17,6 +17,7 @@ #' @return a dataframe with the expected fields added #' #' @import xgboost +#' @import recipes #' #' @export ep_predict <- function(preprocessed_pbp, version = c("latest", "v1.0.0")) { diff --git a/R/ep_preprocess.R b/R/ep_preprocess.R index f72c651..0022d15 100644 --- a/R/ep_preprocess.R +++ b/R/ep_preprocess.R @@ -8,9 +8,9 @@ #' @examples #' \donttest{ #' try({ # catch failures for CRAN purposes -#' preprocessed <- readRDS(system.file("pbp_download.rds",package = "ffopportunity")) -#' # this file is equivalent to nflreadr::load_pbp(2021) %>% head(100) -#' ep_preprocess(preprocessed) +#' pbp_download <- readRDS(system.file("pbp_download.rds",package = "ffopportunity")) +#' # this file is equivalent to nflreadr::load_pbp(2021) %>% head(1000) +#' ep_preprocess(pbp_download) #' }) #' } #' diff --git a/R/ep_version.R b/R/ep_version.R index 85c5887..32dc662 100644 --- a/R/ep_version.R +++ b/R/ep_version.R @@ -14,7 +14,7 @@ ep_cache_models <- function(version = c("latest","v1.0.0"), force = FALSE, ask = cache_dir <- rappdirs::user_cache_dir(appname = "ffopportunity", appauthor = "ffverse") - if(!dir.exists(cache_dir)) dir.create(cache_dir) + if(!dir.exists(cache_dir)) dir.create(cache_dir, recursive = TRUE) if(!force){ if(file.exists(file.path(cache_dir,version))) return(invisible(NULL)) diff --git a/inst/pbp_download.rds b/inst/pbp_download.rds index 411ec16..c9dfeb0 100644 Binary files a/inst/pbp_download.rds and b/inst/pbp_download.rds differ diff --git a/man/ep_preprocess.Rd b/man/ep_preprocess.Rd index 5b2a62e..dc424cc 100644 --- a/man/ep_preprocess.Rd +++ b/man/ep_preprocess.Rd @@ -20,9 +20,9 @@ expected points predictions on \code{nflreadr} data \examples{ \donttest{ try({ # catch failures for CRAN purposes - preprocessed <- readRDS(system.file("pbp_download.rds",package = "ffopportunity")) - # this file is equivalent to nflreadr::load_pbp(2021) \%>\% head(100) - ep_preprocess(preprocessed) + pbp_download <- readRDS(system.file("pbp_download.rds",package = "ffopportunity")) + # this file is equivalent to nflreadr::load_pbp(2021) \%>\% head(1000) + ep_preprocess(pbp_download) }) } diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..ad1f3cd --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,22 @@ +suppressPackageStartupMessages({ + library(testthat) +}) + +gha_online <- !is.null(curl::nslookup("github.com", error = FALSE)) + +skip <- !gha_online + +if(gha_online){ + tryCatch( + expr = { + ep_cache_models(version = "v1.0.0") + pbp_2020 <- nflreadr::load_pbp(2020) + }, + warning = function(e) skip <<- TRUE, + error = function(e) skip <<- TRUE + ) +} + +skippy <- function() NULL +if (skip) skippy <- function() testthat::skip(message = "Unable to connect to GHA") + diff --git a/tests/testthat/test-ep_build.R b/tests/testthat/test-ep_build.R new file mode 100644 index 0000000..aa5674a --- /dev/null +++ b/tests/testthat/test-ep_build.R @@ -0,0 +1,17 @@ +test_that("ep_build and ep_load work", { + skippy() + ep_2020 <- ep_build(2020, version = "v1.0.0") + expect_s3_class(ep_2020,"ffopps_build") + expect_gte(nrow(ep_2020$ep_weekly), 5000) + expect_gte(nrow(ep_2020$ep_pbp_pass), 18000) + expect_gte(nrow(ep_2020$ep_pbp_rush), 13000) + + ep_weekly <- ep_load(2020, type = "weekly",version = "v1.0.0") + ep_pbp_pass <- ep_load(2020, type = "pbp_pass",version = "v1.0.0") + ep_pbp_rush <- ep_load(2020, type = "pbp_rush",version = "v1.0.0") + + expect_equal(nrow(ep_2020$ep_weekly), nrow(ep_weekly)) + expect_equal(nrow(ep_2020$ep_pbp_pass), nrow(ep_pbp_pass)) + expect_equal(nrow(ep_2020$ep_pbp_rush), nrow(ep_pbp_rush)) + +}) diff --git a/tests/testthat/test-ep_calculate.R b/tests/testthat/test-ep_calculate.R deleted file mode 100644 index 8849056..0000000 --- a/tests/testthat/test-ep_calculate.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) -}) diff --git a/tests/testthat/test-ep_load.R b/tests/testthat/test-ep_load.R deleted file mode 100644 index 8849056..0000000 --- a/tests/testthat/test-ep_load.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) -}) diff --git a/tests/testthat/test-preprocess.R b/tests/testthat/test-preprocess.R deleted file mode 100644 index 8849056..0000000 --- a/tests/testthat/test-preprocess.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) -})