问题
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