R CMD BATCH - exit in terminal

Just learning R and I thought it would be great to use it in batch mode in a unix terminal instead of writing in an 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 the file test.r.Rout. I can get it to output the text of a text file by running R CMD BATCH test.r out.txt.

The question is, is it possible to print the output to the terminal?

+3


source to share


2 answers


Sebastian-C came out:

    Rscript test.r

      



This worked in terminal and produced the desired output

Thanks Sebastian-C

+6


source


A somewhat late reaction, but the other day I was looking for the answer to Blakedallen's question. 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 named pipe "fifo" can be used again for any future R CMD BATCH commands you may issue. After the "R CMD BATCH" command, the "cat" command also ends.

0


source







All Articles