How to avoid displaying headers in STOUT from R data.table?
I am trying to avoid displaying headers in the R STOUT output data.table
. Akrun says that on a linked branch, a null route might be possible with print
.
If you don't agree with the NULL route, you may need to create a custom function to print by modifying the existing print
Code
library(data.table)
# http://stackoverflow.com/a/43706344/54964
DF[time < 8]
Output where I want to escape the first header line in STOUT
# Field time T Experiment time_expected timeN
# 1: Acute 0.0 0 A 6 0.000000
+3
source to share
1 answer
We can use 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 a blank 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 can be avoided trimws
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
+5
source to share