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

Partial palette name matching could be smarter #73

Closed
grantmcdermott opened this issue Aug 22, 2023 · 1 comment · Fixed by #74
Closed

Partial palette name matching could be smarter #73

grantmcdermott opened this issue Aug 22, 2023 · 1 comment · Fixed by #74

Comments

@grantmcdermott
Copy link
Owner

We currently allow for palette matching regardless of case (e.g., "r4" <-> "R4").

But, unlike, the main palette() and hcl.colors() functions, we don't do a good job of partial matching (e.g., with an unambiguous first word like palette("tableau") or hcl.colors(5, "zissou")). It's probably a good idea just to use the same charmatch approach that the latter two functions have adopted internally.

@zeileis
Copy link
Collaborator

zeileis commented Aug 23, 2023

Yes, I agree. This should work in https://github.com/grantmcdermott/plot2/blob/main/R/by_aesthetics.R#L42-L46

      fx <- function(x) tolower(gsub("[-, _, \\,, (, ), \\ , \\.]", "", x))
      if (!is.na(charmatch(fx(palette), fx(palette.pals())))) {
        palette_fun = palette.colors
      } else if (!is.na(charmatch(fx(palette), fx(hcl.pals())))) {
        palette_fun = hcl.colors
      } else {
      ...

I'm happy to turn this into a proper PR but it may take a couple of days. Hence I wanted to put it here before I forget.

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 a pull request may close this issue.

2 participants