Plotting to stdout

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting to stdout

Oliver-3
Hello,

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.


Ciao,
   Oliver

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Philipp Pagel-5
On Wed, Aug 26, 2009 at 07:53:57PM +0000, 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/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Oliver-3
Philipp Pagel <p.pagel <at> wzw.tum.de> writes:

>
> On Wed, Aug 26, 2009 at 07:53:57PM +0000, 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Gábor Csárdi-2
On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandel<[hidden email]> 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 <[hidden email]>     UNIL DGM

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Romain Francois
On 08/28/2009 01:16 PM, Gábor Csárdi wrote:

>
> On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandel<[hidden email]>  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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Gabor Grothendieck
In reply to this post by Gábor Csárdi-2
On Fri, Aug 28, 2009 at 7:16 AM, Gábor Csárdi<[hidden email]> wrote:

> On Fri, Aug 28, 2009 at 1:06 PM, Oliver Bandel<[hidden email]> 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Gábor Csárdi-2
On Fri, Aug 28, 2009 at 1:33 PM, Gabor
Grothendieck<[hidden email]> 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 <[hidden email]>     UNIL DGM

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Romain Francois
On 08/28/2009 01:47 PM, Gábor Csárdi wrote:

>
> On Fri, Aug 28, 2009 at 1:33 PM, Gabor
> Grothendieck<[hidden email]>  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
>

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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting to stdout

Jeffrey Horner
In reply to this post by Gábor Csárdi-2
Gábor Csárdi wrote:

> On Fri, Aug 28, 2009 at 1:33 PM, Gabor
> Grothendieck<[hidden email]> 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

______________________________________________
[hidden email] 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.