Skip to content

Commit

Permalink
Add "x more rows" footer for printing data frames
Browse files Browse the repository at this point in the history
  • Loading branch information
nanxstats committed Feb 22, 2024
1 parent b86f2df commit defbe12
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion _common.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ rtf2pdf <- function(input) {

# Customize data frame and tibble printing methods.
# See <https://github.com/elong0527/r4csr/issues/115> for details.
more_rows <- function(x, n) if (nrow(x) <= n) NULL else paste0("# ℹ ", nrow(x) - n, " more rows")
knit_print.data.frame <- function(x, ...) {
paste(capture.output(base::print.data.frame(head(x, 4))), collapse = "\n")
paste(
c(
capture.output(base::print.data.frame(head(x, 4))),
more_rows(x, 4)
),
collapse = "\n"
)
}

registerS3method(
Expand Down

0 comments on commit defbe12

Please sign in to comment.