rprintingdata.tablejustify

How can I instruct R to left justify the text in a character column when displaying a data.table?


How can I instruct R to left justify the text in a character column when displaying a data.table?

For example, how might I instruct R to left justify column "text" in the following output so that it matches the desired output?

library(data.table)
(data1 <- data.table(text = c("AAAAAA", "B", "C"), number = c(1, 2, 3)))
#>      text number
#> 1: AAAAAA      1
#> 2:      B      2
#> 3:      C      3

Created on 2022-02-10 by the reprex package (v2.0.1)

Desired output:

#>    text   number
#> 1: AAAAAA      1
#> 2: B           2
#> 3: C           3

Solution

  • You could pass justify = "left" argument to print.data.table:

    print(data1,justify="left")
         text number
       <char>  <num>
    1: AAAAAA      1
    2: B           2
    3: C           3