Suppose I have an R script:
library('nnet')
something <- runif(50);
print(something)
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.
Last chance thing: If you can spot your another chunck of code starting in your console, you can try pressing the esc key to stop the code running.
The shortcut to interrupt a running process in R depends on the R software and the operating system you are using. However, if you are using RStudio on a Windows computer, you can usually use Esc to stop a currently executing R script. Then, we can press Esc to interrupt the loop.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With