Skip to content

Commit

Permalink
update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Jan 20, 2024
1 parent ca79b9f commit 025f664
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#' @importFrom rlang check_installed abort
NULL

check_palette <- function(palette, names) {
check_palette <- function(palette, names, call = rlang::caller_env()) {
if (!(palette %in% names)) {
abort(
paste0(
"Palette not found. Make sure both package and palette ",
'name are spelled correct in the format "package::palette"'
)
'name are spelled correct in the format "package::palette".'
),
call = call
)
}
}
2 changes: 1 addition & 1 deletion R/paletteer_c.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @export
paletteer_c <- function(palette, n, direction = 1) {
if (abs(direction) != 1) {
abort("direction must be 1 or -1")
abort("`direction` must be 1 or -1.")
}

palette <- try(palette, silent = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/paletteer_d.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
paletteer_d <- function(palette, n, direction = 1,
type = c("discrete", "continuous")) {
if (abs(direction) != 1) {
abort("direction must be 1 or -1")
abort("`direction` must be 1 or -1.")
}

type <- match.arg(type)
Expand Down
4 changes: 2 additions & 2 deletions R/paletteer_dynamic.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#' @export
paletteer_dynamic <- function(palette, n, direction = 1) {
if (abs(direction) != 1) {
abort("direction must be 1 or -1")
abort("`direction` must be 1 or -1.")
}

if (missing(n)) {
abort("n not found. Please supply the number of colors you want returned.")
abort("`n` not found. Please supply the number of colors you want returned.")
}

palette <- try(palette, silent = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/paletteer_d.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Code
paletteer_d("paletteer::notreal")
Condition
Error in `check_palette()`:
! Palette not found. Make sure both package and palette name are spelled correct in the format "package::palette"
Error in `paletteer_d()`:
! Palette not found. Make sure both package and palette name are spelled correct in the format "package::palette".

0 comments on commit 025f664

Please sign in to comment.