R CMD BATCH - output in terminal

人走茶凉 提交于 2019-12-23 10:55:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!