3

I am trying to avoid showing headers in R's STOUT of data.table output. Akrun says in the related thread the the null route may be possible with print.

If you are not okay with the NULL route, then you may have to create a custom function for print by modifying the existing print

Code

library(data.table)

# http://stackoverflow.com/a/43706344/54964

DF[time < 8]

Output where I want to avoid the first header line in STOUT

#    Field time  T Experiment time_expected    timeN
# 1: Acute  0.0  0          A             6 0.000000
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

1 Answers1

5

We can use the unname

unname(DF[time <8])[]

# 1: Acute 0.0  0 A 6 0.000000
# 2:    An 7.7 26 B 6 1.283333
# 3:    Fo 0.0  0 B 5 0.000000
# 4: Acute 7.5  1 C 6 1.250000
# 5:    An 7.9 43 C 6 1.316667
# 6:    En 0.0  0 C 6 0.000000
# 7:    Fo 5.4  1 C 5 1.080000
# 8:    An 7.8 77 D 6 1.300000
# 9:    En 0.0  0 D 6 0.000000
#10:    Fo 0.0  0 D 5 0.000000
#11: Acute 0.0  0 E 6 0.000000
#12:    An 7.9 60 E 6 1.316667
#13:    Fo 0.0  0 E 5 0.000000
#14:    Fo 7.9  3 F 5 1.580000

One option to avoid the empty line would be

cat(trimws(capture.output(unname(DF[time <8]))[-1]) , sep="\n")
#1: Acute 0.0  0 A 6 0.000000
#2:    An 7.7 26 B 6 1.283333
#3:    Fo 0.0  0 B 5 0.000000
#4: Acute 7.5  1 C 6 1.250000
#5:    An 7.9 43 C 6 1.316667
#6:    En 0.0  0 C 6 0.000000
#7:    Fo 5.4  1 C 5 1.080000
#8:    An 7.8 77 D 6 1.300000
#9:    En 0.0  0 D 6 0.000000
#10:    Fo 0.0  0 D 5 0.000000
#11: Acute 0.0  0 E 6 0.000000
#12:    An 7.9 60 E 6 1.316667
#13:    Fo 0.0  0 E 5 0.000000
#14:    Fo 7.9  3 F 5 1.580000

For better formatting, the trimws could be avoided

cat(capture.output(unname(DF[time <8]))[-1] , sep="\n")
# 1: Acute 0.0  0 A 6 0.000000
# 2:    An 7.7 26 B 6 1.283333
# 3:    Fo 0.0  0 B 5 0.000000
# 4: Acute 7.5  1 C 6 1.250000
# 5:    An 7.9 43 C 6 1.316667
# 6:    En 0.0  0 C 6 0.000000
# 7:    Fo 5.4  1 C 5 1.080000
# 8:    An 7.8 77 D 6 1.300000
# 9:    En 0.0  0 D 6 0.000000
#10:    Fo 0.0  0 D 5 0.000000
#11: Acute 0.0  0 E 6 0.000000
#12:    An 7.9 60 E 6 1.316667
#13:    Fo 0.0  0 E 5 0.000000
#14:    Fo 7.9  3 F 5 1.580000
akrun
  • 874,273
  • 37
  • 540
  • 662