Skip to content

Improve on cols_hide() messages on edge cases and allow empty input #1632

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

Merged
merged 7 commits into from
Apr 24, 2024

Conversation

olivroy
Copy link
Collaborator

@olivroy olivroy commented Apr 24, 2024

Summary

Add cols_hide() and put better user-facing messages when something goes wrong. Follow-up to #1342

Outstanding

exibble |> gt() |> cols_hide(everything()) still gives an ugly error, but I will leave that to you!

Edit: I just discovered that it worked as expected in gt 0.10.0, but stopped working in gt 0.10.1.

It now gives Error in has_rtl[i, ] : subscript out of bounds

Not affected by this PR.

Question

Is there a way to bench mark gt?

# Rough testing proved that my change improved speed, but not convinced..
gt(exibble) |> cols_hide(columns =  fctr)

Improved messages

# before
gt(exibble) |> cols_hide(columns = fcd) 
#> Error in resolve_cols_i(expr = { : Can't select columns that don't exist.
#> ✖ Column `fcd` doesn't exist.

# this PR
Error in `cols_hide()`:
! Can't select columns that don't exist.Column `fcd` doesn't exist.

Related GitHub Issues and PRs

Checklist

@olivroy olivroy changed the title Improve on cols_hide() messages on edge cases Improve on cols_hide() messages on edge cases and allow empty input Apr 24, 2024
@rich-iannone rich-iannone self-requested a review April 24, 2024 22:30
@rich-iannone
Copy link
Member

I found that the cols_move*() fns had similar issues with incorrect documentation. I pushed a commit that applies the same behavior as cols_hide() but I'm thinking now that those functions should instead error if there is nothing supplied to columns (the last commit here returns data unchanged).

Do you think there should be shared behavior between the column moving and hiding functions?

@olivroy
Copy link
Collaborator Author

olivroy commented Apr 24, 2024

I like having cols_hide() working (it worked in 0.10.0)

because

exibble |>
  gt()
  cols_hide(
    fctr
  )

But then if you change your mind, you can just comment it out.

That's actually how I came across this bug.

exibble |>
  gt()
  cols_hide(
    # fctr
  )

I have never used cols_move(). I tend to use relocate() in dplyr steps instead.

However, as a reference, data |> relocate() does nothing.

So, I like how you handled it in the last commit.

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 5358d4e into rstudio:master Apr 24, 2024
12 checks passed
@olivroy
Copy link
Collaborator Author

olivroy commented Apr 24, 2024

I know it is difficult without a reprex, but do you have any clue on where to start for #1635. It is actually the reason why I made these contributions today.

It has given me headaches for almost a week now. I am still pretty much clueless (apart from using 0.10.0, which I don't really like)

If anything of what I mentioned there rings a bell, please let me know!

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.

cols_hide() has a documentation issue and error msg
2 participants