Skip to content
Prev 138196 / 398506 Next

plotting to stdout (while reading from stdin?)

Hi Dirk,

I didn't at first pay attention to your comment about littler, as my 
original problem of plotting to stdout was solved. But it was just part of 
the larger problem: I actually need to be piping the data with the code 
for making the picture in, and getting the picture out without opening any 
files. This is to be run in a server environment, where the use of temp 
files is not really acceptable.

Having solved half of the problem, I feel cornered again, because I 
haven't found a nice way of mixing code and data in R.

I am aware that this issue was brought up before; I am not sure I like the 
solutions suggested, because they involve the R language parsing and 
interpreting for each data row -- if I understand correctly.

   http://tolstoy.newcastle.edu.au/R/help/03a/6750.html

Are these solutions the best currently available? That thread is almost 5 
years old now.

Let me give you an example of what I would like to be possible:

In postgres, I can read this from stdin:

    CREATE TABLE remark (
      "case" smallint,
      text text
    );

    COPY remark ("case", text) FROM stdin;
    877     lymph node biopsy
    909     Unresectable mass in the body of the pancreas
    \.

    ... more SQL ....

It allows the "code" and "input" chunks to be mixed, because the 
input for stdin is always terminated by a special token, '\.', and so the 
parser can skip the data chunks without interpreting them.

Almost similarly, perl has the __DATA__ token, that allows a portion of 
text within a program to be treated as stdin.

I wonder whether anything like this is possible in R or littler.


Thanks,

--Gene
On Fri, 7 Sep 2007, Dirk Eddelbuettel wrote: