问题
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?
回答1:
Sebastian-C posted:
Rscript test.r
This worked in the terminal and produced the desired output
Thanks Sebastian-C
回答2:
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.
来源:https://stackoverflow.com/questions/14432637/r-cmd-batch-output-in-terminal