Re: [R] Plotting to stdout
Philipp Pagel p.pagel at wzw.tum.de writes: On Wed, Aug 26, 2009 at 07:53:57PM +, Oliver Bandel wrote: is there a way to write the result of a plot to stdout? I mean even a binary thingy like a png-file, written to stdout?! I tried with the file-argument of png() and jpeg(), but did not get working results. I don't think you can do that. But if you could elaborate on your ultimate goal, perhaps someone can provide an alternative solution. [...] The goal was to produce a picture in a web-environment. At the moment rpy2 will be used maybe there are way to achieve something like that in this way, but I'm also new to rpy2. When the graphic could be written to stdout, the calling environment could reead it from the forked process. But maybe rpy2 works different. Any ideas on that on-the-fly creation of pictures? If there would be no temporary files this would be fine. That's the reason why I looked for stdout as output channel. Ciao, Oliver __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandeloli...@first.in-berlin.de wrote: [...] The goal was to produce a picture in a web-environment. At the moment rpy2 will be used maybe there are way to achieve something like that in this way, but I'm also new to rpy2. When the graphic could be written to stdout, the calling environment could reead it from the forked process. But maybe rpy2 works different. Any ideas on that on-the-fly creation of pictures? If there would be no temporary files this would be fine. That's the reason why I looked for stdout as output channel. Oliver, I have a similar problem and had a similar question on the list about a week ago all I could find out that some devices of the Cairo package are supposed to support plotting to R connections (including stdout), but it does not work in practice: library(Cairo) tc - textConnection(foo, w) CairoPNG(file=tc) Error in Cairo(width, height, type = png, file = filename, pointsize = pointsize, : file must be a filename. to support writing to a connection, recompile R and Cairo with the R Connection Patch. Information on the R connection Patch is welcome. Recompiling R and Cairo is not a problem for me, I am putting together a special environment anyway. Best, Gabor [...] -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
On 08/28/2009 01:16 PM, Gábor Csárdi wrote: On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandeloli...@first.in-berlin.de wrote: [...] The goal was to produce a picture in a web-environment. At the moment rpy2 will be used maybe there are way to achieve something like that in this way, but I'm also new to rpy2. When the graphic could be written to stdout, the calling environment could reead it from the forked process. But maybe rpy2 works different. Any ideas on that on-the-fly creation of pictures? If there would be no temporary files this would be fine. That's the reason why I looked for stdout as output channel. Oliver, I have a similar problem and had a similar question on the list about a week ago all I could find out that some devices of the Cairo package are supposed to support plotting to R connections (including stdout), but it does not work in practice: library(Cairo) tc- textConnection(foo, w) CairoPNG(file=tc) Error in Cairo(width, height, type = png, file = filename, pointsize = pointsize, : file must be a filename. to support writing to a connection, recompile R and Cairo with the R Connection Patch. Information on the R connection Patch is welcome. Recompiling R and Cairo is not a problem for me, I am putting together a special environment anyway. Best, Gabor [...] This is a patch that was offered by Jeff Horner some time ago ; http://tolstoy.newcastle.edu.au/R/e2/devel/06/10/0565.html http://wiki.r-project.org/rwiki/doku.php?id=developers:r_connections_api The patch allows packages to exploit the connection api from the C level, a privilege that still remains internal to R. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/xkMc : Combine R CMD build and junit |- http://tr.im/w33B : Completion for java objects `- http://tr.im/vzip : Code Snippet : List of CRAN packages __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
On Fri, Aug 28, 2009 at 7:16 AM, Gábor Csárdicsa...@rmki.kfki.hu wrote: On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandeloli...@first.in-berlin.de wrote: [...] The goal was to produce a picture in a web-environment. At the moment rpy2 will be used maybe there are way to achieve something like that in this way, but I'm also new to rpy2. When the graphic could be written to stdout, the calling environment could reead it from the forked process. But maybe rpy2 works different. Any ideas on that on-the-fly creation of pictures? If there would be no temporary files this would be fine. That's the reason why I looked for stdout as output channel. Oliver, I have a similar problem and had a similar question on the list about a week ago all I could find out that some devices of the Cairo package are supposed to support plotting to R connections (including stdout), but it does not work in practice: library(Cairo) tc - textConnection(foo, w) CairoPNG(file=tc) Error in Cairo(width, height, type = png, file = filename, pointsize = pointsize, : file must be a filename. to support writing to a connection, recompile R and Cairo with the R Connection Patch. Information on the R connection Patch is welcome. Recompiling R and Cairo is not a problem for me, I am putting together a special environment anyway. Best, Gabor [...] I could have used this functionality in a previous project as well; however, for Oliver's application just pass the filename to the python program use that in the img src=... tag (or have the python program pass the filename to the R program). If there is some aspect of this problem that has not been explained that truly does make passing the graphic file contents to the python program desirable then have R write out the graphic file and then have R read it back in. __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
On Fri, Aug 28, 2009 at 1:33 PM, Gabor Grothendieckggrothendi...@gmail.com wrote: [...] I could have used this functionality in a previous project as well; however, for Oliver's application just pass the filename to the python program use that in the img src=... tag (or have the python program pass the filename to the R program). If there is some aspect of this problem that has not been explained that truly does make passing the graphic file contents to the python program desirable then have R write out the graphic file and then have R read it back in. Unfortunately, this is not always a good solution. For example, I am running Rserve with connections from untrusted users. The Rserve process is not allowed to write to the disk at all, but then there is no easy way to create plots. The patch Romain mentioned above looks like a good solution. Gabor -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
On 08/28/2009 01:47 PM, Gábor Csárdi wrote: On Fri, Aug 28, 2009 at 1:33 PM, Gabor Grothendieckggrothendi...@gmail.com wrote: [...] I could have used this functionality in a previous project as well; however, for Oliver's application just pass the filename to the python program use that in theimg src=... tag (or have the python program pass the filename to the R program). If there is some aspect of this problem that has not been explained that truly does make passing the graphic file contents to the python program desirable then have R write out the graphic file and then have R read it back in. Unfortunately, this is not always a good solution. For example, I am running Rserve with connections from untrusted users. The Rserve process is not allowed to write to the disk at all, but then there is no easy way to create plots. The patch Romain mentioned above looks like a good solution. Gabor There is also the xGD package: http://www.rforge.net/xGD/ Instead of writing to a file, R drawing commands are sent to a TCP/IP socket. There is an example of a java graphics server which you can use to render the graph. I would still like to have some connections API at the c level, for this and other things ... Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/xkMc : Combine R CMD build and junit |- http://tr.im/w33B : Completion for java objects `- http://tr.im/vzip : Code Snippet : List of CRAN packages __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
Gábor Csárdi wrote: On Fri, Aug 28, 2009 at 1:33 PM, Gabor Grothendieckggrothendi...@gmail.com wrote: [...] I could have used this functionality in a previous project as well; however, for Oliver's application just pass the filename to the python program use that in the img src=... tag (or have the python program pass the filename to the R program). If there is some aspect of this problem that has not been explained that truly does make passing the graphic file contents to the python program desirable then have R write out the graphic file and then have R read it back in. Unfortunately, this is not always a good solution. For example, I am running Rserve with connections from untrusted users. The Rserve process is not allowed to write to the disk at all, but then there is no easy way to create plots. The patch Romain mentioned above looks like a good solution. The R connections patch worked well on Unix at the time, but it was never tested on the other R supported platforms. I believe this was R core's complaint about not considering it as a patch. There's yet another option, although someone would need knowledge of converting raw image data to PNG (or other) format in memory: the Cairo package allows access to the raw image data from R itself, although it's undocumented and experimental. The functions are defined in R/imgtools.R within the Cairo source package. Jeff __ R-help@r-project.org 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.
Re: [R] Plotting to stdout
On Wed, Aug 26, 2009 at 07:53:57PM +, Oliver Bandel wrote: is there a way to write the result of a plot to stdout? I mean even a binary thingy like a png-file, written to stdout?! I tried with the file-argument of png() and jpeg(), but did not get working results. I don't think you can do that. But if you could elaborate on your ultimate goal, perhaps someone can provide an alternative solution. cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/ __ R-help@r-project.org 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.
Re: [R] 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: On Fri, Sep 07, 2007 at 02:27:00PM -0400, Duncan Murdoch wrote: On 9/7/2007 2:15 PM, Gene Selkov wrote: Thanks a ton, Duncan! So I have verified that this line works: echo postscript(file=\\, command=\cat\); plot(0) | r --vanilla --slave Wonderful! (albeit a little unobvious) I would include an explicit dev.off() after the plotting; I'm not sure all devices guarantee a clean shutdown when R quits. And for the record, both littler and Rscript can do that without the need for double quotes, at least under Linux. E.g. both $ r -e 'postscript(file=, command=cat); plot(0)' | head $ Rscript -e 'postscript(file=, command=cat); plot(0)' | head provide the same output (of the beginning of the postscript output). Our r is as usual somewhat faster, not that this matters in this non-repeat context. Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org 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.
Re: [R] plotting to stdout (while reading from stdin?)
On Sun, 2 Mar 2008, Gabor Grothendieck wrote: You can do this: Lines - A,B 1,2 3,4 DF - read.csv(textConnection(Lines)) which is slightly simpler than the examples there. Thank you Gabor, I made it even simpler by replacing the Lines object with a string contstant. It works perfectly well for me. Cheers, --Gene On Sun, Mar 2, 2008 at 5:59 PM, Gene Selkov [EMAIL PROTECTED] wrote: 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: On Fri, Sep 07, 2007 at 02:27:00PM -0400, Duncan Murdoch wrote: On 9/7/2007 2:15 PM, Gene Selkov wrote: Thanks a ton, Duncan! So I have verified that this line works: echo postscript(file=\\, command=\cat\); plot(0) | r --vanilla --slave Wonderful! (albeit a little unobvious) I would include an explicit dev.off() after the plotting; I'm not sure all devices guarantee a clean shutdown when R quits. And for the record, both littler and Rscript can do that without the need for double quotes, at least under Linux. E.g. both $ r -e 'postscript(file=, command=cat); plot(0)' | head $ Rscript -e 'postscript(file=, command=cat); plot(0)' | head provide the same output (of the beginning of the postscript output). Our r is as usual somewhat faster, not that this matters in this non-repeat context. Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org 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. __ R-help@r-project.org 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.