Skip to content

print.trunc.cols off by one? #7716

Description

@tdhock

Is this an off by one bug?

> options(datatable.print.trunc.cols=TRUE)
> options(width=10)
> (dt7=data.table(x="1234567"))
1 variable not shown: [x]
> (dt6=data.table(x="123456"))
        x
1: 123456

Above we see dt6 is 9 characters wide (6 characters of data and 3 of row number, colon, space), and dt7 gets truncated, even though I expected that it should print (we have enough space for it with width=10).

Below we see that dt7 prints if we set width=11, which enables printing of this 10 character wide table.

> options(width=11)
> dt7
         x
1: 1234567

Does the current code count the trailing newline as one of the characters toward the width limit? (I expect it should not)

For reference, ?print.data.table says

trunc.cols: If ‘TRUE’, only the columns that can be printed in the
          console without wrapping the columns to new lines will be
          printed (similar to ‘tibbles’).

?options says

     ‘width’:
          controls the maximum number of columns on a line used in

Activity

  1. tdhock commented on Apr 21, 2026

    @tdhock
    MemberAuthor

    same thing happens with column names,

    > options(datatable.print.trunc.cols=TRUE)
    > options(width=10)
    > (n6 <- data.table("123456"="a"))
       123456
    1:      a
    > (n7 <- data.table("1234567"="a"))
    1 variable not shown: [1234567]
    > options(width=11)
    > n7
       1234567
    1:       a
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