Skip to content

prettier print of data.table #1091

Description

@jangorecki

A FR for mainly character processing just right before the print.
When DT is already filtered to non more than 100 rows (default print nrow).
There might be character processing, like:
a) detect and handle \n
b) trunc character after x nchars

library(data.table)

dt <- data.table(a = 1:3, b = c("asda\nzxcz","asdas","CREATE TABLE ASD AS\nSELECT *\nFROM DUAL"))
dt # current
#    a                                        b
#1: 1                               asda\nzxcz
#2: 2                                    asdas
#3: 3 CREATE TABLE ASD AS\nSELECT *\nFROM DUAL

options("datatable.print.word.wrap"=TRUE)
dt # handle \n
#    a                     b
#1: 1                asda ¬
#2: 2                 asdas
#3: 3 CREATE TABLE ASD AS ¬

options("datatable.print.word.wrap"=FALSE,
        "datatable.print.trunc.char"=5L) # default value: 252
dt # handle long characters
#    a        b
#1: 1 asda\...
#2: 2    asdas
#3: 3 CREAT...

Of course it would be only a print, the data.table returned would contains all the data.

Activity

  1. arunsrinivasan commented on Mar 26, 2015

    @arunsrinivasan
    Member

    @jangorecki like this very much.. do you think you can issue a PR? Else, I'll take a look at it.

  2. arunsrinivasan commented on Mar 26, 2015

    @arunsrinivasan
    Member

    What'd also be nice to somehow some the column type while printing as well.. I've had this on my mind for a while. Instead of doing str() or sapply(DT, class)..

  3. added a commit that references this issue on Apr 1, 2015
    f15ac77
  4. added a commit that references this issue on Apr 12, 2015
    c9f55ee
  5. added a commit that references this issue on May 3, 2015
    b4b5bba
  6. arunsrinivasan commented on May 3, 2015

    @arunsrinivasan
    Member

    Have to:

    • add test,
    • assign NULL to global options in onLoad.R and
    • global option to datatable.prettyprint.char.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions