From 0e306032b9895788a7d8cebfeba3292a2e851f9d Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Thu, 7 Nov 2024 13:55:27 -0600 Subject: [PATCH] fix bug in `.pal_init()` with default role --- R/init-pal.R | 2 +- R/utils.R | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/init-pal.R b/R/init-pal.R index cf54efd..b8bf8e9 100644 --- a/R/init-pal.R +++ b/R/init-pal.R @@ -48,7 +48,7 @@ ..., .ns = "elmer" ) { - check_role(role) + check_role(role, allow_default = TRUE) if (!role %in% list_pals()) { cli::cli_abort(c( "No pals with role {.arg {role}} registered.", diff --git a/R/utils.R b/R/utils.R index 389bcee..ef088fb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -32,7 +32,9 @@ list_pals <- function() { } # ad-hoc check helpers ------- -check_role <- function(role, call = caller_env()) { +check_role <- function(role, + allow_default = !is.null(getOption(".pal_on_load")), + call = caller_env()) { check_string(role, allow_empty = FALSE, call = call) if (!is_valid_role(role)) { @@ -42,7 +44,7 @@ check_role <- function(role, call = caller_env()) { ) } - if (role %in% default_roles & is.null(getOption(".pal_on_load"))) { + if (role %in% default_roles & !allow_default) { cli::cli_abort( "Default roles cannot be edited or removed.", call = call