Skip to content

Commit

Permalink
refactor: use {cli} in measures.R
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Apr 4, 2024
1 parent 6187c4b commit 9baa9e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ License: GPL (>= 2)
URL: https://docs.ropensci.org/riem/, https://github.com/ropensci/riem
BugReports: https://github.com/ropensci/riem/issues
Imports:
cli,
httr2,
jsonlite (>= 0.9.19),
lubridate (>= 1.9.0.9000),
Expand All @@ -41,5 +42,5 @@ Suggests:
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.1.2
Remotes:
Remotes:
tidyverse/lubridate
8 changes: 4 additions & 4 deletions R/measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ riem_measures <- function(
date_start <- format_and_check_date(date_start, "date_start")
date_end <- format_and_check_date(date_end, "date_end")
if (date_end < date_start) {
rlang::abort("date_end has to be bigger than date_start")
cli::cli_abort("{.arg date_end} must be bigger than {.arg date_start}.")
}

resp <- perform_riem_request(
Expand Down Expand Up @@ -102,7 +102,7 @@ riem_measures <- function(
)

if (nrow(result) == 0) {
rlang::warn("No results for this query.")
cli::cli_warn("No results for this query.")
return(NULL)
}

Expand All @@ -115,9 +115,9 @@ format_and_check_date <- function(date, name) {
converted_date <- suppressWarnings(lubridate::ymd(date))

if (is.na(converted_date)) {
rlang::abort(
cli::cli_abort(
message = c(
x = sprintf("Invalid %s: %s.", name, date),
x = sprintf("Invalid {.arg %s}: {.value %s}.", name, date),
i = "Correct format is YYYY-MM-DD."
)
)
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/measures.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# riem_measures checks dates

x Invalid date_start: somethingelse.
x Invalid `date_start`: somethingelse.
i Correct format is YYYY-MM-DD.

---

x Invalid date_end: somethingelse.
x Invalid `date_end`: somethingelse.
i Correct format is YYYY-MM-DD.

---

x Invalid date_start: 2015 31 01.
x Invalid `date_start`: 2015 31 01.
i Correct format is YYYY-MM-DD.

---

x Invalid date_end: 2015 31 01.
x Invalid `date_end`: 2015 31 01.
i Correct format is YYYY-MM-DD.

---

date_end has to be bigger than date_start
`date_end` must be bigger than `date_start`.

0 comments on commit 9baa9e4

Please sign in to comment.