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

Error early if rows could not resolve to anything in data_color() #1660

Merged
merged 5 commits into from
May 15, 2024

Conversation

olivroy
Copy link
Contributor

@olivroy olivroy commented May 13, 2024

Summary

Consider this,

mtcars |>
  gt() |>
  data_color(rows = cyl == 5)

Currently, this errors with a cryptic error:

Error in `get_contrast_ratio()`:
! At least one color defined for each of
  `color_1` and `color_2`.

I have left a review with an alternative approach! Please let me know which one you think is better

Related GitHub Issues and PRs

Discovered while answering #1659

Checklist

Copy link
Contributor Author

@olivroy olivroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative PR! (would not be a breaking change, since this currently errors)

Maybe less suprising this way.. I think I prefer the alternative solution, what do you think?

R/data_color.R Outdated Show resolved Hide resolved
tests/testthat/test-data_color.R Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
@rich-iannone
Copy link
Member

This is a bit tricky API-wise. I like the erroring if you supply a specific row index, row name, or set of them. However, if providing an expression it would be nice to no-op, which is just like the behavior for columns. For rows, I don't know that we currently make the distinction between expression and explicit selection. Also, I don't know if this is the current behavior for other functions with a rows argument (mostly fmt_*() and IIRC some cols_*() fns too).

So, it's worth discussing this a little! I know what I proposed would be a breaking change but I hope it would be a welcome one that fixes some inconsistencies.

@olivroy
Copy link
Contributor Author

olivroy commented May 15, 2024

Good idea!

In this case, let's go with the alternative PR (that is the status quo with more informative error)? and I will open a new issue to do that in a folow-up PR.

@olivroy olivroy changed the title return early if rows could not resolve to anything in data_color() Error early if rows could not resolve to anything in data_color() May 15, 2024
NEWS.md Outdated Show resolved Hide resolved
@rich-iannone
Copy link
Member

Disregard the above suggestion, as we're going with a different PR (feel free to close this one).

@olivroy
Copy link
Contributor Author

olivroy commented May 15, 2024

Will you open a new PR? The "alternative" PR is this PR in its current state, after I accepted the suggestions #1660 (review).

My suggestion would be to merge this which basically just changes

# before
mtcars |>
  gt() |>
  data_color(rows = cyl == 5)

Error in `get_contrast_ratio()`:
! At least one color defined for each of
  `color_1` and `color_2`.

# this PR
mtcars |>
  gt() |>
  data_color(rows = cyl == 5)

Error in `data_color()`:
!  `rows` resulted in an empty selection.

And address outstanding issue in a follow-up (issue #1665 )?

Does that make sense?

Co-authored-by: Richard Iannone <riannone@me.com>
@rich-iannone
Copy link
Member

Yes, it makes sense! (Sorry for the confusion here.)

Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rich-iannone rich-iannone merged commit b2d4c75 into rstudio:master May 15, 2024
12 checks passed
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