Closed elong0527 closed 7 months ago
Modified from customize the printing of objects in chunks in R Markdown Cookbook:
knit_print.data.frame <- function(x, ...) {
paste(capture.output(base::print.data.frame(head(x, 5))), collapse = "\n")
}
registerS3method(
"knit_print", "data.frame", knit_print.data.frame,
envir = asNamespace("knitr")
)
You can add the above to _common.R to customize the printing method.
_common.R
is sourced at the beginning of most chapters.
Remember to remove the existing head()
calls.
I had an impression there is a way to control default output while printing data frame. That can potentially remove the
head
function to enhance readability.