How to suppress output
I would like to suppress output in R when I run my R script from the command prompt.
I tried numerous options incl开发者_Python百科uding --slave
and --vanilla
. Those options lessens the amount of text outputted.
I also tried to pipe the output to NUL
but that didn't help.
Look at help(sink)
to do that. On Unix I'd do
sink("/dev/null") # now suppresses
.... # do stuff
sink() # to undo prior suppression, back to normal now
and the Windows equivalent (with a tip-of-the-hat to Johannes) is
sink("NUL")
....
sink()
Since R (>= 3.6.0), there exists a platform-independent alternative to Dirk Eddelbuettel's answer. Simply type
sink(nullfile()) # suppress output
.... # your code
sink() # end suppressing output
to suppress output on both Linux and Windows.
精彩评论