Examples for 'data.table::print.data.table'


data.table Printing Options

Aliases: print.data.table

Keywords:

### ** Examples

  #output compression
  DT <- data.table(a = 1:1000)
  print(DT, nrows = 100, topn = 4)
         a
   1:    1
   2:    2
   3:    3
   4:    4
  ---     
 997:  997
 998:  998
 999:  999
1000: 1000
  #`quote` can be used to identify whitespace
  DT <- data.table(blanks = c(" 12", " 34"),
                   noblanks = c("12", "34"))
  print(DT, quote = TRUE)
   "blanks" "noblanks"
1:    " 12"       "12"
2:    " 34"       "34"
  #`class` provides handy column type summaries at a glance
  DT <- data.table(a = vector("integer", 3),
                   b = vector("complex", 3),
                   c = as.IDate(paste0("2016-02-0", 1:3)))
  print(DT, class = TRUE)
       a      b          c
   <int> <cplx>     <IDat>
1:     0   0+0i 2016-02-01
2:     0   0+0i 2016-02-02
3:     0   0+0i 2016-02-03
  #`row.names` can be eliminated to save space
  DT <- data.table(a = 1:3)
  print(DT, row.names = FALSE)
 a
 1
 2
 3
  #`print.keys` can alert which columns are currently keys
  DT <- data.table(a=1:3, b=4:6, c=7:9, key="b,a")
  setindexv(DT, c("a", "b"))
  setindexv(DT, "a")
  print(DT, print.keys=TRUE)
Key: <b, a>
Indices: <a__b>, <a>
   a b c
1: 1 4 7
2: 2 5 8
3: 3 6 9
  # `trunc.cols` will make it so only columns that fit in console will be printed
  #    with a message that states the variables not shown
  old_width = options("width" = 40)
  DT <- data.table(thing_11 = vector("integer", 3),
                   thing_21 = vector("complex", 3),
                   thing_31 = as.IDate(paste0("2016-02-0", 1:3)),
                   thing_41 = "aasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf",
                   thing_51 = vector("integer", 3),
                   thing_61 = vector("complex", 3))
  print(DT, trunc.cols=TRUE)
   thing_11 thing_21   thing_31
1:        0     0+0i 2016-02-01
2:        0     0+0i 2016-02-02
3:        0     0+0i 2016-02-03
3 variables not shown: [thing_41, thing_51, thing_61]
  options(old_width)

[Package data.table version 1.14.2 Index]