Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Fix Check on Ellipsis in format #726

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thothal
Copy link

@thothal thothal commented Feb 14, 2025

The use of rlang::check_dots_empty in format_tbl threw an error when arguments were passed via .... This behaviour seems unintended, as we deliberately pass ... down to tbl_format_setup.

In this fix, we replace rlang::check_dots_empty with rlang::check_dots_used to ensure that all arguments passed to format (or print, for that matter) are utilized. This change prevents dangling arguments while allowing authors to add new arguments to their print functions.

A dedicated test case was added to test-tbl-format.R. We used withr::with_environment to ensure that the temporary tbl_format_setup.my_tibble method can be properly dispatched.

The use of `rlang::check_dots_empty` in `format_tbl` threw an error
when arguments were passed via `...`. This behaviour seems unintended,
as we deliberately pass `...` down to `tbl_format_setup`.

In this fix, we replace `rlang::check_dots_empty` with
`rlang::check_dots_used` to ensure that all arguments passed to `format`
(or `print`, for that matter) are utilized. This change prevents
dangling arguments while allowing authors to add new arguments to their
print functions.

A dedicated test case was added to `test-tbl-format.R`. We used
`withr::with_environment` to ensure that the temporary
`tbl_format_setup.my_tibble` method can be properly dispatched.
@thothal
Copy link
Author

thothal commented Feb 14, 2025

Ok, I see that the added test cases fails (it passes locally for whatever obscure reason). It must have something to do with he availability of tbl_format_setup.my_tibble. I will replace that with a much easier test case which basically skips the test on know arguments but only tests the error to be thrown for unknown arguments.

In the previous commit, we included a test case for checking the
ellipsis in `format`. While the test passed on the local system, it
failed on the remote system.

The reason is most likely the availability of the S3 method
`tbl_format_setup.my_tibble`. We already needed a special
`withr::with_environment` construct locally to make the test pass.
However, this does not properly guarantee availability on the remote
system.

Thus, we simply removed the specialized test case for a custom class and
only show the basic case where we expect an error, but not the case
where we do not expect an error.
@krlmlr
Copy link
Member

krlmlr commented Feb 14, 2025

@lionel-: Do you think this is a good use case for check_dots_used()?

@krlmlr krlmlr requested a review from lionel- February 14, 2025 09:55
Copy link
Member

@lionel- lionel- left a comment

Choose a reason for hiding this comment

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

Makes sense!

Should probably document in ?print.tbl (top of that file) that ... is passed down to tbl_format_setup()(both fromprint()and fromformat()`)

@@ -77,3 +77,10 @@ test_that("get_width_print()", {
expect_equal(get_width_print(80), 80)
expect_equal(get_width_print(140), 140)
})

test_that("format() signals an error if not all arguments in `...`are used", {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a motivating test case for passing down an argument to a tbl_format_setup() method?

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.

3 participants