Skip to content

Commit 7fd46b1

Browse files
committed
Apply check in functions
1 parent d6ebd4c commit 7fd46b1

File tree

4 files changed

+4
-23
lines changed

4 files changed

+4
-23
lines changed

R/all-classes.R

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,8 @@ class_labels <- S7::new_class(
253253
"labels", parent = class_S3_gg,
254254
constructor = function(labels = list(), ...) {
255255
warn_dots_empty()
256+
check_named(labels, I("labels"))
256257
S7::new_object(labels)
257-
},
258-
validator = function(self) {
259-
if (!is.list(self)) {
260-
return("labels must be a list.")
261-
}
262-
if (!is_named2(self)) {
263-
return("every label must be named.")
264-
}
265-
dups <- unique(names(self)[duplicated(names(self))])
266-
if (length(dups) > 0) {
267-
dups <- oxford_comma(dups, final = "and")
268-
return(paste0("labels cannot contain duplicate names (", dups, ")."))
269-
}
270-
return(NULL)
271258
}
272259
)
273260

R/limits.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@
8181
#'
8282
lims <- function(...) {
8383
args <- list2(...)
84-
85-
if (!is_named2(args)) {
86-
cli::cli_abort("All arguments must be named.")
87-
}
84+
check_named(args, arg = I("Arguments"))
8885
env <- current_env()
8986
Map(limits, args, names(args), rep(list(env), length(args)))
9087
}

R/theme-elements.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,7 @@ check_element_tree <- function(x, arg = caller_arg(x), call = caller_env()) {
746746
if (length(x) < 1) {
747747
return(invisible(NULL))
748748
}
749-
750-
if (!is_named(x)) {
751-
cli::cli_abort("{.arg {arg}} must have names.", call = call)
752-
}
749+
check_named(x, arg = arg, call = call)
753750

754751
# All elements should be constructed with `el_def()`
755752
fields <- names(el_def())

tests/testthat/_snaps/limits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# limits() throw meaningful errors
22

3-
All arguments must be named.
3+
Arguments must have names.
44

55
---
66

0 commit comments

Comments
 (0)