-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,17 @@ print_tbl <- function(x, width = NULL, ..., | |
n = NULL, max_extra_cols = NULL, max_footer_lines = NULL) { | ||
if (!is.null(n_extra)) { | ||
deprecate_stop("1.6.2", "pillar::print(n_extra = )", "pillar::print(max_extra_cols = )") | ||
if (is.null(max_extra_cols)) { | ||
max_extra_cols <- n_extra | ||
} | ||
} | ||
|
||
writeLines(format( | ||
# Printing happens as a side effect thanks to `transform = writeLines` . | ||
# For formatting, the default `transform = identity` returns the data instead. | ||
format_tbl( | ||
x, | ||
width = width, ..., | ||
n = n, max_extra_cols = max_extra_cols, max_footer_lines = max_footer_lines | ||
)) | ||
n = n, max_extra_cols = max_extra_cols, max_footer_lines = max_footer_lines, | ||
transform = writeLines | ||
) | ||
|
||
invisible(x) | ||
} | ||
|
||
|
@@ -48,7 +49,8 @@ format_tbl <- function( | |
n_extra = NULL, | ||
n = NULL, | ||
max_extra_cols = NULL, | ||
max_footer_lines = NULL | ||
max_footer_lines = NULL, | ||
transform = identity | ||
) { | ||
check_dots_empty(action = signal) | ||
|
||
|
@@ -60,17 +62,53 @@ format_tbl <- function( | |
force(x) | ||
num_colors(forget = TRUE) | ||
|
||
setup <- tbl_format_setup(x, | ||
width = width, ..., | ||
# This is a bit of a hack to allow the setup function to be called twice | ||
# if the implementer is prepared to handle that. | ||
# We detect that by checking if the `setup` argument has been evaluated. | ||
setup_used <- FALSE | ||
|
||
# In either case, we expect a `setup` object that can be passed to `tbl_format_header()` | ||
# as a return from this call. | ||
setup <- tbl_format_setup( | ||
x, | ||
width = width, | ||
..., | ||
setup = { | ||
# This construct updates the `setup_used` variable in the parent scope | ||
# when the `setup` argument is evaluated. | ||
setup_used <- TRUE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a note in here about the fact that "If |
||
NULL | ||
}, | ||
n = n, | ||
max_extra_cols = max_extra_cols, | ||
max_footer_lines = max_footer_lines, | ||
focus = attr(x, "pillar_focus") | ||
) | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adding a comment to that effect to the code. |
||
|
||
# If the implementation did not request the `setup` argument in the first call, | ||
# the default behavior before 1.9.1 is used: the first call already | ||
# has returned the full setup object. | ||
# Otherwise, we assume that a second call is required, and we pass it the | ||
# setup object returned from the first call. | ||
if (setup_used) { | ||
setup <- tbl_format_setup( | ||
x, | ||
width = width, | ||
..., | ||
setup = setup, | ||
n = n, | ||
max_extra_cols = max_extra_cols, | ||
max_footer_lines = max_footer_lines, | ||
focus = attr(x, "pillar_focus") | ||
) | ||
} | ||
|
||
# In either case, the `setup` object is now complete and can be used to format the body | ||
# and the footer. | ||
body <- transform(tbl_format_body(x, setup)) | ||
footer <- transform(tbl_format_footer(x, setup)) | ||
c(header, body, footer) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
# Revdeps | ||
|
||
## Failed to check (1) | ||
|
||
|package |version |error |warning |note | | ||
|:----------|:-------|:-----|:-------|:----| | ||
|tidyseurat |0.8.0 |1 | | | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
## revdepcheck results | ||
|
||
We checked 122 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. | ||
We checked 3 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. | ||
|
||
* We saw 0 new problems | ||
* We failed to check 1 packages | ||
* We failed to check 0 packages | ||
|
||
Issues with CRAN packages are summarised below. | ||
|
||
### Failed to check | ||
|
||
* tidyseurat (NA) |
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