This is possible using the cairoDevice package and RGtk2.

Turning an R graphic into a raw vector of bytes:

library(cairoDevice)
library(RGtk2)

# create a pixmap and tell cairoDevice to draw to it

pixmap <- gdkPixmapNew(w=500, h=500, depth=24)
asCairoDevice(pixmap)

# make a dummy plot

plot(1:10)

# convert the pixmap to a pixbuf

plot_pixbuf <- gdkPixbufGetFromDrawable(NULL, pixmap, pixmap$getColormap(),
0, 0, 0, 0, 500, 500)

# save the pixbuf to a raw vector

buffer <- gdkPixbufSaveToBufferv(plot_pixbuf, "jpeg", character(0),
character(0))$buffer

###

Then you can send buffer to your database, or whatever. Replacing "jpeg"
with "png" will probably produce png output.

Michael

On Nov 15, 2007 3:32 PM, Greg Snow <[EMAIL PROTECTED]> wrote:

> You might try looking at the tkrplot package, it uses win.metafile and
> captures the graphics device into a variable (which is then put into a
> tk lable, but you could probably do something else with it).
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [EMAIL PROTECTED]
> (801) 408-8111
>
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Josh Tolley
> > Sent: Thursday, November 15, 2007 2:08 PM
> > To: r-help@r-project.org
> > Subject: [R] Graphics device storable in a variable
> >
> > I'm using R embedded in PostgreSQL (via PL/R), and would like
> > to use it to create images. It works fine, except that I have
> > to create every image in a file (owned by and only readable
> > by the PostgreSQL server), and then use PostgreSQL to read
> > from that file and return it to the client. It would be much
> > nicer if I could plot images into an R variable (for
> > instance, a matrix), and return that variable through the
> > PostgreSQL client. Leaving aside the details of returning the
> > data to PostgreSQL (which I realize are beyond the scope of
> > this list), I envision R code along the lines of the following:
> >
> > # Create a png device, a handle to which is stored in myDevice
> > > myDevice <- png.variable(height = 1280, width = 1024, bg = "white")
> > # Plot some data into the current device
> > > plot(myX, myY, col="red")
> > # Finalize
> > > dev.off()
> > # Print out the contents of myDevice
> > > myDevice
> >
> > ...and the data would print out just like any other matrix or
> > class or whatever type myDevice actually is.
> >
> > So my question is does such a thing already exist? I know
> > about piximage, but apparently I have to load image data from
> > somewhere for it to work; I can't use plot(), etc. to create
> > the piximage data. GDD would be a nice way to do it, because
> > GD libraries are widely available for use with other
> > languages I might use with PostgreSQL and PL/R (for instance,
> > Perl would talk to PostgreSQL, call a PL/R function to use R
> > to return an image, which Perl would then process further),
> > but GDD requires temporary files as well, as far as I can
> > see. Thanks for any help anyone can offer.
> >
> > -Josh / eggyknap
> >
> > ______________________________________________
> > 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to