Redirect stdout to a txt file in R without the prompt

扶醉桌前 提交于 2020-01-06 08:21: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.

来源:https://stackoverflow.com/questions/38132675/redirect-stdout-to-a-txt-file-in-r-without-the-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!