Skip to content

Commit

Permalink
ensure_one(): reduce noise if attrs are NULL
Browse files Browse the repository at this point in the history
ignore NULL values
  • Loading branch information
alyst committed Mar 20, 2019
1 parent eb2caca commit db622ad
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions R/subplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,18 @@ dots2plots <- function(...) {
# helper function that warns if more than one plot-level attribute
# has been specified in a list of plots (and returning that attribute)
ensure_one <- function(plots, attr) {
attrs <- lapply(plots, "[", attr)
attrs <- Filter(Negate(is.null), lapply(plots, "[[", attr))
if (length(attrs) == 0) {
warning("No ", attr, " found", call. = FALSE)
return (NULL)
}
for (i in seq_along(attrs)) {
if (!identical(attrs[[1]], attrs[[i]])) {
warning("Can only have one: ", attr, call. = FALSE)
break
}
}
attrs[[length(attrs)]][[1]]
attrs[[length(attrs)]]
}


Expand Down

0 comments on commit db622ad

Please sign in to comment.