Just learning R and I thought it would be great to use it in batch mode in the unix terminal instead of writing in the R terminal.
So I decided to write test.r
x <- 2
print(x)
then in terminal I did
R CMD BATCH test.r
it runs, But outputs a test.r.Rout file. I can get it to output to say a text file by running R CMD BATCH test.r out.txt.
Question is, is it possible to print the output to the terminal?
R provides a way to run a large set of commands in sequence and save the results to a file. This is called batch mode. One way to run R in batch mode is from the system command line (not the R console). By running R from the system command line, it's possible to run a set of commands without starting R.
R is an interpreted programming language. This means that R will interpret each line of code as it is entered and, if it is valid, R will execute it, returning the result in the command console.
Sebastian-C posted:
Rscript test.r
This worked in the terminal and produced the desired output
Thanks Sebastian-C
A somewhat late reaction, but the other day I was looking for the answer to exactly the question Blakedallen posted. Here's my solution:
mkfifo fifo # create a named pipe
cat fifo & # show everything to the terminal
# (or do 'cat fifo' in another terminal)
R CMD BATCH input # 'input' contains your R commands
Works like a charm :-)
The 'fifo' named pipe can be used again for any future R CMD BATCH commands you may want to execute. After the 'R CMD BATCH' command the 'cat' command also ends.
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