How to avoid showing headers in STOUT of R data.table?

后端 未结 1 969
天涯浪人
天涯浪人 2021-01-20 07:13

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

1条回答
  •  醉话见心
    2021-01-20 07:24

    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
    

    0 讨论(0)
提交回复
热议问题