Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace usethis by cli #33

Merged
merged 2 commits into from
Jan 16, 2024
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions R/bugs-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
53 changes: 29 additions & 24 deletions R/format-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
))
}
}

Expand All @@ -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 {

Expand All @@ -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}}"
))
}
}

Expand Down Expand Up @@ -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}}"
))
}
}

Expand All @@ -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]}}"
))
}
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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, ]
}
Expand Down
43 changes: 23 additions & 20 deletions R/series-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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(location_detected)}} series with {.val {location}}."
)
}

data[series_match]
Expand Down
Loading