3

I tried to plot a beeswarm plot (http://www.cbs.dtu.dk/~eklund/beeswarm/) and I got it to work and now I want to write a small R script to automate things. The input I want to give to this R script is from STDIN and I'm having trouble to get data read from STDIN.

Here is my R script:

args <- commandArgs(TRUE)
f1 <- args[1]

plotbeeswarm <- function(output){
    library(beeswarm)
    f <- read.table(stdin(), header=TRUE)
    png(output, width=800, height=800)
    beeswarm(Data ~ Category, data=f, pch=16, pwcol=1+as.numeric(sample), 
             xlab="")
}

plotbeeswarm(f1)

The problem I think is just how the input file was read and processed into f. Can anyone help me fix my code? Thanks very much!

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
olala
  • 4,146
  • 9
  • 34
  • 44

1 Answers1

2

Here is an example I use on the webpage for littler and which you should be able to adapt for Rscript too:

The code of the script is just:

#!/usr/bin/r -i

fsizes <- as.integer(readLines(file("stdin")))
print(summary(fsizes))
stem(fsizes)

and I feed the result from ls -l into, filtered by awk to get just one column of file sizes:

edd@max:~/svn/littler/examples$ ls -l /bin/ | awk '{print $5}' | ./fsizes.r 
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
      3    6240   30820   61810   60170 2000000       1 

  The decimal point is 5 digit(s) to the right of the |

   0 | 00000000000000000000000000000000000111111111111111111111111122222222+57
   1 | 111112222345679
   2 | 7
   3 | 1
   4 | 1
   5 | 
   6 | 
   7 | 
   8 | 
   9 | 6
  10 | 
  11 | 
  12 | 
  13 | 
  14 | 
  15 | 
  16 | 
  17 | 
  18 | 
  19 | 
  20 | 0

edd@max:~/svn/littler/examples$ 
John Blischak
  • 1,102
  • 1
  • 14
  • 18
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725