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

Deprecating ... in format.tbl inhibts custom arguments to print generic #725

Open
thothal opened this issue Feb 13, 2025 · 3 comments
Open

Comments

@thothal
Copy link

thothal commented Feb 13, 2025

Disclaimer: I posted this first on SO but I really think the discussion should be happening here.

With the changes introduced in pillar 1.10.0 ... must now be empty in printing and formatting.

I am now, however, wondering, how one would allow additional arguments in print to be properly handled. Here's a motivating example:

mt <- tibble::new_tibble(mtcars[1:3, ], my_attr = "set", class = "my_tibble")

tbl_format_setup.my_tibble <- function(x, ..., show_attr = TRUE) {
  setup <- NextMethod()
  if (show_attr) {
    setup$tbl_sum <- c(setup$tbl_sum, "Attribute" = attr(x, "my_attr"))
  }
  setup
}

Overloading tbl_format_setup should enable the user to opt-out from printing the additional line. However, this information must be passed down to the function somehow. Pre 1.10 we could simply use the ellipsis from print:

print(mt, show_attr = FALSE)

This still works but throws the warning.

I think it is a valid use-case to add some more sub-class specific arguments to print and let the underlying workhorse functions handle them appropriately. To avoid the warning altogether, I have to make a clone of print.tbl which does not call format_tbl directly anymore, but where I copy and paste the code from format_tbl undoing the ellipsis check.

So I either I am overlooking the obvious, or this change actively wants to stop us from adding custom arguments to print. Thus, some clarification would be really helpful (even if it is yes, we do not want you morons to add arguments to print for this and that reason ;) )

@krlmlr
Copy link
Member

krlmlr commented Feb 13, 2025

Thanks. This has been a silent check_dots_empty(), and if this causes trouble, we can think this over. I wonder if this is a case for check_dots_used() instead of check_dots_empty() . Would you like to take a look?

@thothal
Copy link
Author

thothal commented Feb 14, 2025

Could you elaborate the reasoning behind check_dots_(used|empty)?

I would assume that we want to allow the usage of ellipsis, because it would enable the package authors to extend print as outlined (and in fact you are already passing down ... to tbl_format_setup anyways), so I guess this behavior is intended. Thus, making sure that there are no additional arguments in ... (as per check_dots_empty) does not make sense to me.

check_dots_used on the other hand seems to make much more sense. We allow for the usage of ..., but we want to ensure that we do not pass arguments which are nowhere consumed.

Happy to hear your thoughts on that?

@thothal
Copy link
Author

thothal commented Feb 14, 2025

Ok, I had a look at it and check_dots_used seems to be a viable solution. Create PR #726.

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

No branches or pull requests

2 participants