-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: tbl_format_setup()
gains a setup
argument that supports printing the header before the data for the body is available, e.g., for remote backends such as databases
#686
Conversation
This is likely to affect dbplyr by no longer showing the number of rows in the header if it's less than 21. I'd trade that for showing the header first. And I wonder if we should temporarily show the structure of the data too, and erase it (with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels quite "spooky" to me
In particular I found relying on "did setup
get evaluated or not" a bit hard to understand and document.
Is it possible that new_tbl_format_setup()
could gain a boolean argument that identifies whether or not this is a "partial" setup?
Like:
- If we see
is.null(setup)
then we do partial setup and return withpartial = TRUE
. - That causes
tbl_format_setup()
to get called again, but with!is.null(setup)
this time (i.e. it gets the results of the original partial setup), so we do the full setup and return withpartial = FALSE
width = width, | ||
..., | ||
setup = { | ||
setup_used <- TRUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a note in here about the fact that "If setup
is evaluated by the tbl_format_setup()
method, then that's our signal to recall tbl_format_setup()
a second time"
header <- tbl_format_header(x, setup) | ||
body <- tbl_format_body(x, setup) | ||
footer <- tbl_format_footer(x, setup) | ||
header <- transform(tbl_format_header(x, setup)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does transform()
do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transform
is writeLines
when printing and identity
when formatting. This is how we achieve incremental printing.
Adding a comment to that effect to the code.
@@ -41,6 +41,14 @@ | |||
#' This argument is mandatory for all implementations of this method. | |||
#' @param ... | |||
#' Extra arguments to [print.tbl()] or [format.tbl()]. | |||
#' @param setup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth a news bullet
Thanks. I see how it's spooky, I couldn't think of a better way. We want to be compatible with existing implementations of |
tbl_format_setup()
gains a setup
argument that supports printing the header before the data for the body is available, e.g., for remote backends such as databases
Going with this implementation for now, we can revisit as needed. |
This supports printing the header before the body or footer is ready. Adding the
setup
argument totbl_format_setup()
was the easiest way I found to achieve this. The two commits are self-contained.