Skip to content

datatable.prettyprint.char could use ellipsis (…) instead of three dots #7715

Description

@tdhock

this is a silly trivial example, but

> options(datatable.prettyprint.char=2, datatable.print.class=FALSE)
> data.table(x="foo")
       x
1: fo...
> options(datatable.prettyprint.char=3, datatable.print.class=FALSE)
> data.table(x="foo")
     x
1: foo

The first output above is actually wider than the second. (5 characters instead of 3, surprising, because it is supposed to abbreviate)

could we change to below output? (still three characters)

     x
1: fo…

Activity

  1. tdhock commented on Apr 21, 2026

    @tdhock
    MemberAuthor

    related to #5425

  2. ben-schwen commented on May 29, 2026

    @ben-schwen
    Member

    Not sure using ellipsis is the best option here, since locales without UTF-8 support will then display strange characters.

    Also AFAIK ellipsis is a double-width character in certain Asian fonts and this might break alignment of columns?

  3. tdhock commented on May 29, 2026

    @tdhock
    MemberAuthor

    those are valid points. what locales, specifically? can you please provide a code example?

  4. ben-schwen commented on May 29, 2026

    @ben-schwen
    Member

    Things that should not work are ASCII or latin1.

    iconv("\u2026", "UTF-8", "ASCII")
    # [1] NA
    iconv("\u2026", "UTF-8", "latin1")
    # [1] NA

    I guess we could check with l10n_info()$'UTF-8' and fall back to three dots.

  5. ben-schwen commented on May 31, 2026

    @ben-schwen
    Member

    Also ccing @aitap here as he knows more about encodings

  6. tomasy-j commented on May 31, 2026

    @tomasy-j

    Hello @ben-schwen @tdhock , thank you for your remarks.

    Not sure using ellipsis is the best option here, since locales without UTF-8 support will then display strange characters.

    Also AFAIK ellipsis is a double-width character in certain Asian fonts and this might break alignment of columns?

    I updated the related PR so it falls back to three dots when locale is not UTF-8, seems to be working with locales that don't support it, e.g:

    Sys.setlocale("LC_CTYPE", "Chinese")
    > l10n_info()$`UTF-8`
    [1] FALSE
    
    options(datatable.prettyprint.char=2, datatable.print.class=FALSE)
    data.table::data.table(x="foo")
           x
    1: fo...
    

    Do you have any suggestions how the added if clause should be covered in unit tests? Currently test 2253* is run only for UTF-8 locale. Should any tests be added?
    Thanks!

  7. aitap commented on Jun 1, 2026

    @aitap
    Member

    I was surprised to learn (by grepping libiconv source code for 0x2026) that there are many single-byte encodings in use that include … (e.g. 0x85 in at least some ANSI encodings on Windows). The test should probably be for identical(enc2native("\u2026"), "\u2026"), for which we have the utf8_check helper. I'm afraid the tests for abbreviated output will have to become conditional on that as well.

  8. tdhock commented on Jun 13, 2026

    @tdhock
    MemberAuthor

    using #7788 I see up to six dots in a row. three dots from list abbreviation, then another three from prettyprint

    > options(width = 17, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                    L
               <list>
    1: 1,2,3,4,5,6...
    > options(width = 18, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                     L
                <list>
    1: 1,2,3,4,5,6,...
    > options(width = 19, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                      L
                 <list>
    1: 1,2,3,4,5,6,....
    > options(width = 20, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                       L
                  <list>
    1: 1,2,3,4,5,6,.....
    > options(width = 21, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                        L
                   <list>
    1: 1,2,3,4,5,6,......
    > options(width = 22, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                         L
                    <list>
    1: 1,2,3,4,5,6,...[...
    > options(width = 23, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                          L
                     <list>
    1: 1,2,3,4,5,6,...[2...
    > options(width = 24, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                           L
                      <list>
    1: 1,2,3,4,5,6,...[25...
    > options(width = 25, datatable.prettyprint.char = NULL);data.table(x = "0123456789", L = list(1:25))
                x
           <char>
    1: 0123456789
                         L
                    <list>
    1: 1,2,3,4,5,6,...[25]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions