fix: print() and format() pass on ... to tbl_format_setup() again, as documented#726
Merged
krlmlr merged 6 commits intor-lib:mainfrom Mar 13, 2025
Merged
fix: print() and format() pass on ... to tbl_format_setup() again, as documented#726krlmlr merged 6 commits intor-lib:mainfrom
print() and format() pass on ... to tbl_format_setup() again, as documented#726krlmlr merged 6 commits intor-lib:mainfrom
Conversation
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.
Contributor
Author
|
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 |
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.
Member
|
@lionel-: Do you think this is a good use case for |
lionel-
approved these changes
Feb 19, 2025
Member
lionel-
left a comment
There was a problem hiding this comment.
Makes sense!
Should probably document in ?print.tbl (top of that file) that ... is passed down to tbl_format_setup()(both fromprint()and fromformat()`)
tests/testthat/test-tbl-format.R
Outdated
| expect_equal(get_width_print(140), 140) | ||
| }) | ||
|
|
||
| test_that("format() signals an error if not all arguments in `...`are used", { |
Member
There was a problem hiding this comment.
Maybe add a motivating test case for passing down an argument to a tbl_format_setup() method?
formatprint() and format() pass on ... to tbl_format_setup() again
print() and format() pass on ... to tbl_format_setup() againprint() and format() pass on ... to tbl_format_setup() again, as documented
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The use of
rlang::check_dots_emptyinformat_tblthrew an error when arguments were passed via.... This behaviour seems unintended, as we deliberately pass...down totbl_format_setup.In this fix, we replace
rlang::check_dots_emptywithrlang::check_dots_usedto ensure that all arguments passed toformat(orprint, 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 usedwithr::with_environmentto ensure that the temporarytbl_format_setup.my_tibblemethod can be properly dispatched.