From dd40c4f94c5d5cb1889922f9763338187ec0e66d Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 12 Jan 2024 10:55:20 -0500 Subject: [PATCH 1/2] replace usethis by cli --- DESCRIPTION | 4 ++-- R/bugs-funs.R | 10 +++++----- R/format-funs.R | 53 +++++++++++++++++++++++++++---------------------- R/series-funs.R | 43 ++++++++++++++++++++------------------- 4 files changed, 59 insertions(+), 51 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f7abcfe..c22349c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,10 +36,10 @@ Imports: grDevices, R2jags, stats, - usethis + cli Suggests: knitr, rmarkdown Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 VignetteBuilder: knitr diff --git a/R/bugs-funs.R b/R/bugs-funs.R index 351eb15..0b75d74 100644 --- a/R/bugs-funs.R +++ b/R/bugs-funs.R @@ -701,14 +701,14 @@ diagnostic <- function(data, threshold = 1.1) { if (length(pos)) { no_converged <- names(bugs)[pos] - - usethis::ui_oops(paste0("Some parameters have not converged for the ", - "following count series: ", - "{usethis::ui_value(no_converged)}.")) + cli::cli_alert_danger(c( + "Some parameters have not converged for the following count series: ", + "{.val {no_converged}}." + )) } else { - usethis::ui_done("All models have converged.") + cli::cli_alert_success("All models have converged.") } invisible(NULL) diff --git a/R/format-funs.R b/R/format-funs.R index 5d2538f..6c18972 100644 --- a/R/format-funs.R +++ b/R/format-funs.R @@ -1118,10 +1118,10 @@ format_data <- function(data, info = NULL, date = "date", count = "count", count_series <- count_series[-which(names(count_series) %in% series_to_del)] if (length(n_rows) < length(count_series)) { - usethis::ui_oops(paste0("Removing the following series without valid ", - "precision measures: ", - usethis::ui_value(paste0(series_to_del, - collapse = ", ")))) + cli::cli_alert_danger(c( + "Removing the following series without valid precision measures: ", + "{.val {series_to_del}}" + )) } } @@ -1135,10 +1135,11 @@ format_data <- function(data, info = NULL, date = "date", count = "count", if (!na_rm) { - stop("The following count series have not enough data (< 4):\n", - usethis::ui_value(paste0(series_to_del, - collapse = ", ")), - "\nRemove these count series or use 'na_rm = TRUE'.") + cli::cli_abort(c( + "The following count series have not enough data (< 4):", + "{.val {series_to_del}}", + i = "Remove these count series or use 'na_rm = TRUE'." + )) } else { @@ -1147,10 +1148,10 @@ format_data <- function(data, info = NULL, date = "date", count = "count", } if (length(n_rows) < length(count_series)) { - usethis::ui_oops(paste0("Removing the following series without enough ", - "data (< 4) ", - usethis::ui_value(paste0(series_to_del, - collapse = ", ")))) + cli::cli_alert_danger(c( + "Removing the following series without enough data (< 4) ", + "{.val {series_to_del}}" + )) } } @@ -1191,10 +1192,10 @@ format_data <- function(data, info = NULL, date = "date", count = "count", count_series <- count_series[-which(names(count_series) %in% series_to_del)] if (length(n_rows) < length(count_series)) { - usethis::ui_oops(paste0("Removing the following series without valid ", - "precision measures: ", - usethis::ui_value(paste0(series_to_del, - collapse = ", ")))) + cli::cli_alert_danger(c( + "Removing the following series without valid precision measures: ", + "{.val {series_to_del}}" + )) } } @@ -1209,9 +1210,10 @@ format_data <- function(data, info = NULL, date = "date", count = "count", if (any(count_series[[i]][ , "lower_ci_conv"] == count_series[[i]][ , "upper_ci_conv"])) { - stop(paste0("Lower and upper CI bounds cannot be strictly equal for ", - "the series.", - usethis::ui_value(names(count_series)[i]))) + cli::cli_abort(c( + "Lower and upper CI bounds cannot be strictly equal for the series.", + "{.val {names(count_series)[i]}}" + )) } } @@ -1270,9 +1272,10 @@ format_data <- function(data, info = NULL, date = "date", count = "count", paste0(id, "_data.RData"))) } - - usethis::ui_done(paste0("Detecting {usethis::ui_value(length(", - "data_series))} count series")) + + cli::cli_alert_success( + "Detecting {.val {length(data_series)}} count series." + ) data_series } @@ -1302,8 +1305,10 @@ is_na_counts <- function(data, col, na_rm) { } else { pos <- which(is.na(data[ , col])) - usethis::ui_info(paste0("Removing {usethis::ui_value(length(pos))} ", - "rows with NA values in '", col, "' field.")) + + cli::cli_alert_info(c( + "Removing {.val {length(pos)}} rows with NA values in {.field {col}} field." + )) data <- data[-pos, ] } diff --git a/R/series-funs.R b/R/series-funs.R index c3fd834..2613b7b 100644 --- a/R/series-funs.R +++ b/R/series-funs.R @@ -34,11 +34,12 @@ get_series <- function(data, quiet = TRUE) { series_infos$"id" <- gsub("[[:punct:]]", "_", series_infos$"id") if (!quiet) - usethis::ui_done(paste0("Detecting {usethis::ui_value(nrow(series_infos))}", - " series with {usethis::ui_value(length(unique(", - "series_infos$location)))} location(s) and ", - "{usethis::ui_value(length(unique(", - "series_infos$species)))} species")) + + cli::cli_alert_success(c( + "Detecting {.val {nrow(series_infos)}} series with ", + "{.val {length(unique(series_infos$location))}} location{?s} and ", + "{.val {length(unique(series_infos$species))}} species." + )) series_infos } @@ -117,8 +118,9 @@ filter_series <- function(data, species = NULL, location = NULL) { if (is.null(species) && is.null(location)) { - usethis::ui_oops(paste0("No species nor location provided to filter ", - "series.")) + cli::cli_alert_danger( + "No species nor location provided to filter series" + ) return(NULL) } @@ -173,15 +175,16 @@ filter_series <- function(data, species = NULL, location = NULL) { series_match <- which(species_detected & location_detected) if (length(series_match)) { - usethis::ui_done(paste0("Found {usethis::ui_value(length(", - "series_match))} series with ", - "{usethis::ui_value(species)} and ", - "{usethis::ui_value(location)}.")) + + cli::cli_alert_success(c( + "Found {.val {length(series_match)}} series with ", + "{.val {species}} and {.val {location}}." + )) } else { - usethis::ui_oops(paste0("No series found with ", - "{usethis::ui_value(species)} and ", - "{usethis::ui_value(location)}.")) + cli::cli_alert_danger( + "No series found with {.val {species}} and {.val {location}}." + ) return(NULL) } @@ -194,18 +197,18 @@ filter_series <- function(data, species = NULL, location = NULL) { series_match <- species_detected - usethis::ui_done(paste0("Found {usethis::ui_value(", - "sum(species_detected))} ", - "series with {usethis::ui_value(species)}.")) + cli::cli_alert_success( + "Found {.val {sum(species_detected)}} series with {.val {species}}." + ) } if (is.null(species) && !is.null(location)) { series_match <- location_detected - usethis::ui_done(paste0("Found {usethis::ui_value(", - "sum(location_detected))} ", - "series with {usethis::ui_value(location)}.")) + cli::cli_alert_success( + "Found {.val {sum(locations_detected)}} series with {.val {location}}." + ) } data[series_match] From 990e7e12e107c59f6c55b6bdfd7c8f3d29befeba Mon Sep 17 00:00:00 2001 From: olivroy Date: Sat, 13 Jan 2024 08:26:39 -0500 Subject: [PATCH 2/2] fix typo --- R/series-funs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/series-funs.R b/R/series-funs.R index 2613b7b..4148631 100644 --- a/R/series-funs.R +++ b/R/series-funs.R @@ -207,7 +207,7 @@ filter_series <- function(data, species = NULL, location = NULL) { series_match <- location_detected cli::cli_alert_success( - "Found {.val {sum(locations_detected)}} series with {.val {location}}." + "Found {.val {sum(location_detected)}} series with {.val {location}}." ) }