Piping stdin to R

后端 未结 3 2131
日久生厌
日久生厌 2020-12-01 08:12

I am having trouble piping stdin to an R script.

Here is my toy script test.R:

#!/usr/bin/env Rscript
while(length(line <- readLines(         


        
3条回答
  •  北海茫月
    2020-12-01 08:30

    This is the easiest I've found (assuming numeric input):

    x <- scan(file("stdin")
    

    you can test it with:

    $ echo -e "1\n2\n3" | R -s -e 'x <- scan(file("stdin")); summary(x)'
    Read 3 items
       Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
        1.0     1.5     2.0     2.0     2.5     3.0 
    

提交回复
热议问题