Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 including --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.

like image 582
defoo Avatar asked Mar 23 '10 16:03

defoo


People also ask

How do I suppress an output in R?

By using invisible() function we can suppress the output.

How do I not show output in bash?

If you are looking to suppress or hide all the output of a bash shell script from Linux command line as well as from the crontab then you can simply redirect all the output to a file known as /dev/null . This file is known as Black Hole which will engulf everything you give without complaining.

How do I reduce grep output?

The quiet option ( -q ), causes grep to run silently and not generate any output. Instead, it runs the command and returns an exit status based on success or failure. The return status is 0 for success and nonzero for failure.

How do I redirect all output to Dev Null?

You can send output to /dev/null, by using command >/dev/null syntax.


2 Answers

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()
like image 135
Dirk Eddelbuettel Avatar answered Sep 21 '22 19:09

Dirk Eddelbuettel


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.

like image 30
Lukas Avatar answered Sep 21 '22 19:09

Lukas