Redirect stdout to a txt file in R without the pro

2019-09-16 13:12发布

I know this has been asked before and the answer has always been to use sink but I'm getting the prompt written out too and I don't want that. Any way to just store the output to a .txt file and not the prompts?

info(hdr) prints the following to console:

> info(hdr)
DataFrame with 3 rows and 3 columns
        Number        Type                 Description
   <character> <character>                 <character>
NS           1     Integer Number of Samples With Data
DP           1     Integer                 Total Depth
DB           0        Flag dbSNP membership, build 131

I want to send all of info()'s output to a .txt file and these are the commands I'm using

sink("info.txt")
info(hdr) 
sink()

What's written in info.txt:

> info(hdr) 
DataFrame with 3 rows and 3 columns
        Number        Type                 Description
   <character> <character>                 <character>
NS           1     Integer Number of Samples With Data
DP           1     Integer                 Total Depth
DB           0        Flag dbSNP membership, build 131

> sink()

Why are the commands showing up too? Anyway to prevent that?

EDIT: for clarity. The function info() comes from VariantAnnotation package from the following link: http://www.bioconductor.org/help/workflows/variants/. The output of str(hdr) is:

Formal class 'VCFHeader' [package "VariantAnnotation"] with 3 slots
  ..@ reference: chr(0) 
  ..@ samples  : chr "GS06985-1100-37-ASM"
  ..@ header   :Formal class 'SimpleDataFrameList' [package "IRanges"] with 4 slots
  .. .. ..@ elementType    : chr "DataFrame"
  .. .. ..@ elementMetadata: NULL
  .. .. ..@ metadata       : list()
  .. .. ..@ listData       :List of 4

Many more lines but I truncated.

标签: r sink
0条回答
登录 后发表回答