John Doucette John Doucette - 1 year ago 65
R Question

How can I avoid having my R script printed every time I run it?

Suppose I have an R script:

something <- runif(50);

When I run this script from the command line, it prints:

> library('nnet')
> something <- runif(5);
> print(something)
[1] 0.04665518 0.93574275 0.96387299 0.07410239 0.92834019

I would like it to print only:

[1] 0.04665518 0.93574275 0.96387299 0.07410239 0.92834019

and I cannot figure out how to do this. sink("/dev/null") doesn't do anything, redirecting stderr manually doesn't do anything, and I can't find any useful information on this.

Answer Source

Resolution is to run with Rscript, and not with R. Examples elsewhere (e.g. How can I read command line parameters from an R script?), run scripts from the command line with

R --args args1 args2... < foo.R

running with

Rscript foo.R args1 args2 ...

produces only the output, and not the script. It's also a much cleaner way to run scripts.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download