Skip to content

Commit

Permalink
improve print.data.table
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed May 6, 2023
1 parent 817cfe1 commit e4a405f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
22 changes: 22 additions & 0 deletions R/print.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# #' @importFrom pillar dim_desc

#' print.data.table
#'
#' @examples
#' d = data.table(1:100)
#' options(datatable.print.nrow = 100)
#' print(d)
#' @export
print.data.table <- function(d, n = NULL, ..., maxrows = 1e6) {
if (is.null(n)) n = getOption("datatable.print.nrow") %||% 10

# cat(sprintf("[data.table]: %s \n", dim_desc(d)))
if (nrow(d) <= maxrows) {
cat("[data.table]: \n")

class(d) <- c("tbl", "data.table", "data.frame")
print(d, n = n, ...)
} else {
data.table:::print.data.table(d)
}
}
15 changes: 0 additions & 15 deletions R/reexports.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,6 @@ data.table::fread
#' @export
data.table::fwrite


# #' @importFrom pillar dim_desc
#' @export
print.data.table <- function(d, n = 10, ..., maxrows = 1e6) {
# cat(sprintf("[data.table]: %s \n", dim_desc(d)))
if (nrow(d) <= maxrows) {
cat("[data.table]: \n")

class(d) <- c("tbl", "data.table", "data.frame")
print(d, n = n, ...)
} else {
data.table:::print.data.table(d)
}
}

#' @export
data.table::as.data.table

Expand Down
16 changes: 16 additions & 0 deletions man/print.data.table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4a405f

Please sign in to comment.