Skip to content

Commit

Permalink
Drop usethis dependency and use cli instead (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb authored Jul 23, 2021
1 parent 9e18261 commit 2a783c6
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 79 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nflfastR
Title: Functions to Efficiently Access NFL Play by Play Data
Version: 4.1.0.9006
Version: 4.1.0.9007
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down Expand Up @@ -38,7 +38,7 @@ BugReports: https://github.com/nflverse/nflfastR/issues
Depends:
R (>= 3.5.0)
Imports:
cli (>= 1.1.0),
cli (>= 3.0.0),
curl,
dplyr,
fastrmodels (>= 1.0.1),
Expand All @@ -56,7 +56,6 @@ Imports:
tibble (>= 3.0),
tidyr (>= 1.0.0),
tidyselect (>= 1.1.0),
usethis (>= 1.6.0),
xgboost (>= 1.1)
Suggests:
crayon (>= 1.3.4),
Expand Down
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,5 @@ importFrom(tidyr,unnest)
importFrom(tidyr,unnest_wider)
importFrom(tidyselect,any_of)
importFrom(tidyselect,ends_with)
importFrom(usethis,ui_done)
importFrom(usethis,ui_info)
importFrom(usethis,ui_oops)
importFrom(usethis,ui_stop)
importFrom(usethis,ui_todo)
importFrom(usethis,ui_value)
importFrom(utils,packageVersion)
importFrom(xgboost,getinfo)
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Fix for `fixed_drive` where it wasn't incrementing following an interception with the intercepting player then losing a fumble (#247)
* Fix for more issues with missing play info in 2018_01_ATL_PHI (#246)
* Added the variables `safety_player_name` and `safety_player_id` to the play-by-play data (#252)
* Dropped the dependency `usethis`

# nflfastR 4.1.0

Expand Down Expand Up @@ -241,8 +242,8 @@ unique player has one unique ID (as they did before the NFL data source change):
(ID: 32013030-2d30-3032-3334-3336b638d37d) are both abbreviated as "A.Smith"
but can be distinguished by their IDs, with Akili showing what the old
format ID looks like, and Smith the new one
* Standardization is realized by using an [ID map](https://github.com/nflverse/nflfastR-data/blob/master/roster-data/legacy_id_map.csv)
available in the data repo created with [this script](https://github.com/nflverse/nflfastR-data/blob/master/roster-data/legacy_id_map.R)
* Standardization is realized by using an ID map
available in the data repo

* `clean_pbp()` now removes all variables it is about to create to make sure
nothing unexpected can happen
Expand Down
14 changes: 7 additions & 7 deletions R/build_nflfastR_pbp.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ build_nflfastR_pbp <- function(game_ids,
lifecycle::deprecate_warn(
when = "4.0.0",
what = "build_nflfastR_pbp(pp = )",
details = glue::glue(
details = cli::cli_text(c(
"We have dropped the in-package activation of parallel processing as ",
"this is considered bad practice.\n",
"Please choose an appropriate plan before calling the function, e.g. ",
"{usethis::ui_code('future::plan(\"multisession\")')}"
)
"{.code future::plan(\"multisession\")}"
))
)
}

if (!is.vector(game_ids) && is.data.frame(game_ids)) game_ids <- game_ids$game_id

if (!is.vector(game_ids)) usethis::ui_stop("Param {usethis::ui_code('game_ids')} is not a valid vector!")
if (!is.vector(game_ids)) cli::cli_abort("Param {.code game_ids} is not a valid vector!")

if (isTRUE(decode) && !is_installed("gsisdecoder")) {
usethis::ui_stop("Package {usethis::ui_value('gsisdecoder')} required for decoding. Please install it with {usethis::ui_code('install.packages(\"gsisdecoder\")')}.")
cli::cli_abort("Package {.val gsisdecoder} required for decoding. Please install it with {.code install.packages(\"gsisdecoder\")}.")
}

if (isTRUE(rules)) rule_header("Build nflfastR Play-by-Play Data")
Expand All @@ -92,9 +92,9 @@ build_nflfastR_pbp <- function(game_ids,
builder <- TRUE

if (game_count > 1) {
usethis::ui_todo("{my_time()} | Start download of {game_count} games...")
cli::cli_ul("{my_time()} | Start download of {game_count} games...")
} else {
usethis::ui_todo("{my_time()} | Start download of {game_count} game...")
cli::cli_ul("{my_time()} | Start download of {game_count} game...")
}

ret <- fast_scraper(game_ids = game_ids, source = source, pp = pp, ..., in_builder = builder) %>%
Expand Down
26 changes: 13 additions & 13 deletions R/helper_database_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ update_db <- function(dbdir = ".",

if (!is_installed("DBI") | !is_installed("purrr") |
(!is_installed("RSQLite") & is.null(db_connection))) {
usethis::ui_stop("{my_time()} | Packages {usethis::ui_value('DBI')}, {usethis::ui_value('RSQLite')} and {usethis::ui_value('purrr')} required for database communication. Please install them.")
cli::cli_abort("{my_time()} | Packages {.val DBI}, {.val RSQLite} and {.val purrr} required for database communication. Please install them.")
}

if (any(force_rebuild == "NEW")) {
usethis::ui_stop("{my_time()} | The argument {usethis::ui_value('force_rebuild = NEW')} is only for internal usage!")
cli::cli_abort("{my_time()} | The argument {.val force_rebuild = NEW} is only for internal usage!")
}

if (!(is.logical(force_rebuild) | is.numeric(force_rebuild))) {
usethis::ui_stop("{my_time()} | The argument {usethis::ui_value('force_rebuild')} has to be either logical or numeric!")
cli::cli_abort("{my_time()} | The argument {.val force_rebuild} has to be either logical or numeric!")
}

if (!dir.exists(dbdir) & is.null(db_connection)) {
usethis::ui_oops("{my_time()} | Directory {usethis::ui_path(dbdir)} doesn't exist yet. Try creating...")
cli::cli_alert_danger("{my_time()} | Directory {.file {dbdir}} doesn't exist yet. Try creating...")
dir.create(dbdir)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ update_db <- function(dbdir = ".",
}

message_completed("Database update completed", in_builder = TRUE)
usethis::ui_info("{my_time()} | Path to your db: {usethis::ui_path(DBI::dbGetInfo(connection)$dbname)}")
cli::cli_alert_info("{my_time()} | Path to your db: {.file {DBI::dbGetInfo(connection)$dbname}}")
if (is.null(db_connection)) DBI::dbDisconnect(connection)
rule_footer("DONE")
}
Expand All @@ -130,23 +130,23 @@ build_db <- function(tblname = "nflfastR_pbp", db_conn, rebuild = FALSE, show_me
dplyr::ungroup()

if (all(rebuild == TRUE)) {
usethis::ui_todo("{my_time()} | Purging the complete data table {usethis::ui_value(tblname)} in your connected database...")
cli::cli_ul("{my_time()} | Purging the complete data table {.val tblname} in your connected database...")
DBI::dbRemoveTable(db_conn, tblname)
seasons <- valid_seasons %>% dplyr::pull("season")
usethis::ui_todo("{my_time()} | Starting download of {length(seasons)} seasons between {min(seasons)} and {max(seasons)}...")
cli::cli_ul("{my_time()} | Starting download of {length(seasons)} seasons between {min(seasons)} and {max(seasons)}...")
} else if (is.numeric(rebuild) & all(rebuild %in% valid_seasons$season)) {
string <- paste0(rebuild, collapse = ", ")
if (show_message){usethis::ui_todo("{my_time()} | Purging {string} season(s) from the data table {usethis::ui_value(tblname)} in your connected database...")}
if (show_message){cli::cli_ul("{my_time()} | Purging {string} season(s) from the data table {.val tblname} in your connected database...")}
DBI::dbExecute(db_conn, glue::glue_sql("DELETE FROM {`tblname`} WHERE season IN ({vals*})", vals = rebuild, .con = db_conn))
seasons <- valid_seasons %>% dplyr::filter(.data$season %in% rebuild) %>% dplyr::pull("season")
usethis::ui_todo("{my_time()} | Starting download of the {string} season(s)...")
cli::cli_ul("{my_time()} | Starting download of the {string} season(s)...")
} else if (all(rebuild == "NEW")) {
usethis::ui_info("{my_time()} | Can't find the data table {usethis::ui_value(tblname)} in your database. Will load the play by play data from scratch.")
cli::cli_alert_info("{my_time()} | Can't find the data table {.val tblname} in your database. Will load the play by play data from scratch.")
seasons <- valid_seasons %>% dplyr::pull("season")
usethis::ui_todo("{my_time()} | Starting download of {length(seasons)} seasons between {min(seasons)} and {max(seasons)}...")
cli::cli_ul("{my_time()} | Starting download of {length(seasons)} seasons between {min(seasons)} and {max(seasons)}...")
} else {
seasons <- NULL
usethis::ui_oops("{my_time()} | At least one invalid value passed to argument {usethis::ui_code('force_rebuild')}. Please try again with valid input.")
cli::cli_alert_danger("{my_time()} | At least one invalid value passed to argument {.val force_rebuild}. Please try again with valid input.")
}

if (!is.null(seasons)) {
Expand All @@ -166,6 +166,6 @@ get_missing_games <- function(completed_games, dbConnection, tablename) {

need_scrape <- completed_games[!completed_games %in% db_ids]

usethis::ui_info("{my_time()} | You have {length(db_ids)} games and are missing {length(need_scrape)}.")
cli::cli_alert_info("{my_time()} | You have {length(db_ids)} games and are missing {length(need_scrape)}.")
return(need_scrape)
}
8 changes: 4 additions & 4 deletions R/helper_decode_player_ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
decode_player_ids <- function(pbp, ..., fast = TRUE) {
if (isFALSE(fast)) {
if (nrow(pbp) > 1000 && is_sequential()) {
usethis::ui_info(c(
cli::cli_alert_info(c(
"It is recommended to use parallel processing when trying to to decode big data frames.",
"Please consider running {usethis::ui_code('future::plan(\"multisession\")')}!",
"Please consider running {.code future::plan(\"multisession\")}! ",
"Will go on sequentially..."
))
}
Expand All @@ -60,10 +60,10 @@ decode_player_ids <- function(pbp, ..., fast = TRUE) {
)
} else if (isTRUE(fast)) {
if (!is_installed("gsisdecoder")) {
usethis::ui_stop("Package {usethis::ui_value('gsisdecoder')} required for fast decoding. Please install it with {usethis::ui_code('install.packages(\"gsisdecoder\")')}.")
cli::cli_abort("Package {.val gsisdecoder} required for fast decoding. Please install it with {.code install.packages(\"gsisdecoder\")}.")
}
# No need to inform that decoding starts since it's very fast
# usethis::ui_todo("Start decoding player ids...")
# cli::cli_ul("Start decoding player ids...")

ret <- pbp %>%
dplyr::mutate_at(
Expand Down
2 changes: 1 addition & 1 deletion R/helper_scrape_gc.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
get_pbp_gc <- function(gameId, dir = NULL, qs = FALSE) {

if (isTRUE(qs) && !is_installed("qs")) {
usethis::ui_stop("Package {usethis::ui_value('qs')} required for argument {usethis::ui_value('qs = TRUE')}. Please install it.")
cli::cli_abort("Package {.val qs} required for argument {.val qs = TRUE}. Please install it.")
}

combined <- data.frame()
Expand Down
2 changes: 1 addition & 1 deletion R/helper_scrape_nfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
get_pbp_nfl <- function(id, dir = NULL, qs = FALSE) {

if (isTRUE(qs) && !is_installed("qs")) {
usethis::ui_stop("Package {usethis::ui_value('qs')} required for argument {usethis::ui_value('qs = TRUE')}. Please install it.")
cli::cli_abort("Package {.val qs} required for argument {.val qs = TRUE}. Please install it.")
}

combined <- data.frame()
Expand Down
10 changes: 5 additions & 5 deletions R/load_pbp.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ load_pbp <- function(seasons, ..., qs = FALSE) {
if (all(c("dbConnection", "tablename") %in% names(dots))) in_db <- TRUE else in_db <- FALSE

if (isTRUE(qs) && !is_installed("qs")) {
usethis::ui_stop("Package {usethis::ui_value('qs')} required for argument {usethis::ui_value('qs = TRUE')}. Please install it.")
cli::cli_abort("Package {.val qs} required for argument {.val qs = TRUE}. Please install it.")
}

most_recent <- most_recent_season()

if (!all(seasons %in% 1999:most_recent)) {
usethis::ui_stop("Please pass valid seasons between 1999 and {most_recent}")
cli::cli_abort("Please pass valid seasons between 1999 and {most_recent}")
}

if (length(seasons) > 1 && is_sequential() && isFALSE(in_db)) {
usethis::ui_info(c(
"It is recommended to use parallel processing when trying to load multiple seasons.",
"Please consider running {usethis::ui_code('future::plan(\"multisession\")')}!",
cli::cli_alert_info(c(
"It is recommended to use parallel processing when trying to load multiple seasons.\n",
"Please consider running {.code future::plan(\"multisession\")}! ",
"Will go on sequentially..."
))
}
Expand Down
2 changes: 1 addition & 1 deletion R/load_player_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
load_player_stats <- function(qs = FALSE) {

if (isTRUE(qs) && !is_installed("qs")) {
usethis::ui_stop("Package {usethis::ui_value('qs')} required for argument {usethis::ui_value('qs = TRUE')}. Please install it.")
cli::cli_abort("Package {.val qs} required for argument {.val qs = TRUE}. Please install it.")
}

if (isTRUE(qs)) {
Expand Down
1 change: 0 additions & 1 deletion R/nflfastR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
#' @importFrom tibble as_tibble tibble
#' @importFrom tidyr unnest_wider unnest
#' @importFrom tidyselect any_of ends_with
#' @importFrom usethis ui_done ui_todo ui_oops ui_info ui_stop ui_value
#' @importFrom utils packageVersion
#' @importFrom xgboost getinfo
## usethis namespace: end
Expand Down
38 changes: 19 additions & 19 deletions R/top-level_scraper.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,24 +416,24 @@ fast_scraper <- function(game_ids,
lifecycle::deprecate_warn(
when = "4.0.0",
what = "fast_scraper(pp = )",
details = glue::glue(
details = cli::cli_text(c(
"We have dropped the in-package activation of parallel processing as ",
"this is considered bad practice.\n",
"Please choose an appropriate plan before calling the function, e.g. ",
"{usethis::ui_code('future::plan(\"multisession\")')}"
)
"{.code future::plan(\"multisession\")}"
))
)
}

if (!is.vector(game_ids) && is.data.frame(game_ids)) game_ids <- game_ids$game_id

if (!is.vector(game_ids)) usethis::ui_stop("Param {usethis::ui_code('game_ids')} is not a valid vector!")
if (!is.vector(game_ids)) cli::cli_abort("Param {.code game_ids} is not a valid vector!")

if (length(game_ids) > 1 && is_sequential()) {
usethis::ui_info(
cli::cli_alert_info(
c(
"It is recommended to use parallel processing when trying to load multiple games.",
"Please consider running {usethis::ui_code('future::plan(\"multisession\")')}!",
"Please consider running {.code future::plan(\"multisession\")}! ",
"Will go on sequentially..."
)
)
Expand Down Expand Up @@ -469,7 +469,7 @@ fast_scraper <- function(game_ids,

if (!in_builder) {
str <- paste0(my_time(), " | Procedure completed.")
usethis::ui_done("{usethis::ui_field(str)}")
cli::cli_alert_success("{.field {str}}")
}
return(pbp)
}
Expand Down Expand Up @@ -524,20 +524,20 @@ fast_scraper_roster <- function(seasons, pp = lifecycle::deprecated()) {
lifecycle::deprecate_warn(
when = "4.0.0",
what = "fast_scraper_roster(pp = )",
details = glue::glue(
details = cli::cli_text(c(
"We have dropped the in-package activation of parallel processing as ",
"this is considered bad practice.\n",
"Please choose an appropriate plan before calling the function, e.g.",
"{usethis::ui_code('future::plan(\"multisession\")')}"
)
"{.code future::plan(\"multisession\")}"
))
)
}

if (length(seasons) > 1 && is_sequential()) {
usethis::ui_info(
cli::cli_alert_info(
c(
"It is recommended to use parallel processing when trying to load multiple seasons.",
"Please consider running {usethis::ui_code('future::plan(\"multisession\")')}!",
"It is recommended to use parallel processing when trying to load multiple seasons. ",
"Please consider running {.code future::plan(\"multisession\")}! ",
"Will go on sequentially..."
)
)
Expand Down Expand Up @@ -598,19 +598,19 @@ fast_scraper_schedules <- function(seasons, pp = lifecycle::deprecated()) {
lifecycle::deprecate_warn(
when = "4.0.0",
what = "fast_scraper_schedules(pp = )",
details = glue::glue(
details = cli::cli_text(c(
"We have dropped the in-package activation of parallel processing as ",
"this is considered bad practice.\n",
"Please choose an appropriate plan before calling the function, e.g.",
"{usethis::ui_code('future::plan(\"multisession\")')}"
)
"{.code future::plan(\"multisession\")}"
))
)
}
if (length(seasons) > 1 && is_sequential()) {
usethis::ui_info(
cli::cli_alert_info(
c(
"It is recommended to use parallel processing when trying to load multiple seasons.",
"Please consider running {usethis::ui_code('future::plan(\"multisession\")')}!",
"It is recommended to use parallel processing when trying to load multiple seasons. ",
"Please consider running {.code future::plan(\"multisession\")}! ",
"Will go on sequentially..."
)
)
Expand Down
Loading

0 comments on commit 2a783c6

Please sign in to comment.