Skip to content

Commit b6a535f

Browse files
committed
Better error message for scope_normalize()
1 parent dbaa169 commit b6a535f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

R/style-guides.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,20 +471,19 @@ tidyverse_reindention <- function() {
471471
#' @param scope A character vector of length one or a vector of class `AsIs`.
472472
#' @param name The name of the character vector to be displayed if the
473473
#' construction of the factor fails.
474-
474+
#'
475475
#' @examples
476476
#' scope_normalize(I("tokens"))
477477
#' scope_normalize(I(c("indention", "tokens")))
478478
#' @family third-party style guide helpers
479479
#' @export
480480
scope_normalize <- function(scope, name = substitute(scope)) {
481-
levels <- c("none", "spaces", "indention", "line_breaks", "tokens")
482-
if (!all((scope %in% levels))) {
483-
abort(paste(
484-
"all values in", name, "must be one of the following:",
485-
toString(levels)
486-
))
487-
}
481+
levels <- c("none", "spaces", "indention", "line_breaks", "tokens")
482+
rlang::arg_match(
483+
scope,
484+
values = levels,
485+
multiple = TRUE
486+
)
488487

489488
if (inherits(scope, "AsIs")) {
490489
factor(as.character(scope), levels = levels, ordered = TRUE)

0 commit comments

Comments
 (0)