Skip to content

Commit db622ad

Browse files
committed
ensure_one(): reduce noise if attrs are NULL
ignore NULL values
1 parent eb2caca commit db622ad

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

R/subplots.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,18 @@ dots2plots <- function(...) {
339339
# helper function that warns if more than one plot-level attribute
340340
# has been specified in a list of plots (and returning that attribute)
341341
ensure_one <- function(plots, attr) {
342-
attrs <- lapply(plots, "[", attr)
342+
attrs <- Filter(Negate(is.null), lapply(plots, "[[", attr))
343+
if (length(attrs) == 0) {
344+
warning("No ", attr, " found", call. = FALSE)
345+
return (NULL)
346+
}
343347
for (i in seq_along(attrs)) {
344348
if (!identical(attrs[[1]], attrs[[i]])) {
345349
warning("Can only have one: ", attr, call. = FALSE)
346350
break
347351
}
348352
}
349-
attrs[[length(attrs)]][[1]]
353+
attrs[[length(attrs)]]
350354
}
351355

352356

0 commit comments

Comments
 (0)