print.trunc.cols off by one?

Open
#7,716 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
r
Domain
data

Research direction

Reproduce the examples using print.data.table, options(width=10), and datatable.print.trunc.cols=TRUE. Inspect how print.data.table accounts for available width and trailing characters; done when dt7 prints at width=10 without wrapping and the boundary behavior is covered by a regression test.

Written by the indexing model from the issue text.

Description

beginner-task print

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
Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.