[R] plotting to stdout
Duncan Murdoch
murdoch at stats.uwo.ca
Fri Sep 7 18:49:09 CEST 2007
On 9/7/2007 12:36 PM, Gene Selkov wrote:
> I have found two prior instances of this question in R-help, but I can't
> find the answer, and I'm giving up on mindless tinkering.
>
> http://tolstoy.newcastle.edu.au/R/help/03a/5994.html
> https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html
>
> I must be able to pipe the poltting commands to stdin and receive the plot
> on stdout, with errors written to stderr, should any occur.
>
> Here's what I tried:
>
> file test.r:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
> postscript(stdout())
> plot(0)
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This command:
>
> cat test.r | r --vanilla --slave
>
> writes the output to a file named "1"
>
> I have also tried:
>
> postscript(file=stdout())
> postscript(file=file("stdout"))
>
> In the latter case, the output goes to the file named "3".
>
> Other graphics devices do the same thing.
>
> It is interesting that write.table() supports the file=stdout() idiom. If
> there is no official option to do this, I will appreciate a hint
> about the spot in the code where I can fix it.
The ?postscript man page suggests that
postscript(file="", command="cat")
should do what you want (or maybe something other than "cat" for the
passthrough). The file arg is described as a character string, not a
connection, so I wouldn't expect stdout() to work. For write.table(),
the arg is defined to be either the name of a file or an open connection.
Duncan Murdoch
>
> Thanks,
>
> --Gene
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> sessionInfo()
> R version 2.5.1 (2007-06-27)
> i386-apple-darwin8.10.1
>
> locale:
> C
>
> attached base packages:
> [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
> [7] "base"
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list