Skip to content

Commit

Permalink
Merge pull request r-lib#27 from wch/brewer-nowarn
Browse files Browse the repository at this point in the history
Suppress warnings for color brewer palettes with <3 colors
  • Loading branch information
wch committed Sep 20, 2012
2 parents 2bd518e + f42c0da commit 4b6db68
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion R/pal-brewer.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@
brewer_pal <- function(type = "seq", palette = 1) {
pal <- pal_name(palette, type)

# If <3 colors are requested, brewer.pal will return a 3-color palette and
# give a warning. This warning isn't useful, so suppress it.
# If the palette has k colors and >k colors are requested, brewer.pal will
# return a k-color palette and give a warning. This warning is useful, so
# don't suppress it. In both cases, the seq_len(n) is there to make sure
# that the n items are returned, even if brewer.pal returns a different
# number of items.
function(n) {
brewer.pal(n, pal)[seq_len(n)]
if (n < 3)
suppressWarnings(brewer.pal(n, pal))[seq_len(n)]
else
brewer.pal(n, pal)[seq_len(n)]
}
}

Expand Down

0 comments on commit 4b6db68

Please sign in to comment.