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

Conversation

wch
Copy link
Member

@wch wch commented Sep 20, 2012

This suppresses warnings when <3 colors are requested, but keeps them when more colors are requested than the palette contains.

@hadley
Copy link
Member

hadley commented Sep 20, 2012

Doesn't scales give it's own warning in some circumstances?

@wch
Copy link
Member Author

wch commented Sep 20, 2012

I'm not sure what you have in mind - this will only suppress warnings from brewer.pal. Looking at the code for brewer.pal, it gives warnings in two circumstances: too few, and too many colors requested. It throws an error when a non-existent palette is requested:

> brewer.pal
function (n, name) 
{
    if (!(name %in% namelist)) {
        stop(paste(name, "is not a valid palette name for brewer.pal\n"))
    }
    if (n < 3) {
        warning("minimal value for n is 3, returning requested palette with 3 different levels\n")
        return(brewer.pal(3, name))
    }
    if (n > maxcolors[which(name == namelist)]) {
        warning(paste("n too large, allowed maximum for palette", 
            name, "is", maxcolors[which(name == namelist)]), 
            "\nReturning the palette you asked for with that many colors\n")
        return(brewer.pal(maxcolors[which(name == namelist)], 
            name))
    }

...

The rest of the code in the function just contains palettes. So I think this patch safely suppresses warnings.

@hadley
Copy link
Member

hadley commented Sep 20, 2012

I think I was getting confused with old ggplot2 code - it looks good.

wch added a commit that referenced this pull request Sep 20, 2012
Suppress warnings for color brewer palettes with <3 colors
@wch wch merged commit 4b6db68 into r-lib:master Sep 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants