Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress warnings for color brewer palettes with <3 colors #27

Merged
merged 1 commit into from Sep 20, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion R/pal-brewer.r
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