Skip to content

print should abbreviate columns larger than options(width)? #7718

Description

@tdhock

Below I ask for width=10 but that is only respected for the first three numeric columns.

> options(width=10, datatable.prettyprint.char=NULL, datatable.print.trunc.cols=FALSE, datatable.print.class=FALSE)
> data.table(V1=1, V2=2, V3=3, x="12345678901234567890", L=list(1:9))
   V1 V2
1:  1  2
   V3
1:  3
                      x
1: 12345678901234567890
                    L
1: 1,2,3,4,5,6,...[9]

both x and L are wider than options(width=10), which seems to violate the definition in ?options:

     ‘width’:
          controls the maximum number of columns on a line used in
          printing vectors, matrices and arrays, and when filling by
          cat.

I would ask to change the output to:

   V1 V2
1:  1  2
   V3
1:  3
         x
1: 123456…
         L
1: 1,2,3,…

Activity

  1. tdhock commented on Apr 21, 2026

    @tdhock
    MemberAuthor

    to be fair, data.frame does no better:

    > data.frame(V1=1, V2=2, V3=3, x="12345678901234567890", L=I(list(1:9)))
      V1 V2
    1  1  2
      V3
    1  3
                         x
    1 12345678901234567890
                 L
    1 1, 2, 3,....

    tibble also goes over the 10 char width

    > tibble::tibble(V1=1, V2=2, V3=3, x="12345678901234567890", L=list(1:9))
    # A
    #   tibble:
    #   1 × 5
         V1
      <dbl>
    1     1
    # ℹ 4
    #   more
    #   variables:
    #   V2 <dbl>,
    #   V3 <dbl>,
    #   x <chr>,
    #   L <list>
  2. tdhock commented on Apr 21, 2026

    @tdhock
    MemberAuthor

    my real use case is parsing text data. sometimes I have a character column with some elements much wider than 80 chars. In that case it would be nice if data table could truncate the character column to that many chars (or slightly smaller to fit).
    maybe we could change the default, would options(datatable.prettyprint.char=getOption("width")-5) be possible?

  3. venom1204 commented on May 24, 2026

    @venom1204
    Contributor

    hi @joshhwuu

    I’m planning to work on this issue, i have a below proposed fix for the issue ,if it sounds good then i will be ready to proceed with the pr .

    The planned changes are:

    • Dynamically setting the default truncation limit based on getOption("width") - 5L when datatable.prettyprint.char is NULL, so narrow consoles avoid line overflow.
    • Applying char.trunc to list-column character representations to ensure long list outputs are also width-limited.

    is this in a right direction or there are any suggestions

  4. tdhock commented on May 25, 2026

    @tdhock
    MemberAuthor

    great thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions