4

I'd like to save a plot image directly to the database.

Is the best way in R to do this:

  1. Write the plot image (png) to the filesystem
  2. Read the file that was written
  3. Send the file to the database via query (RODBC)

Ideally I'd like to combine steps 1 and 2 above by simply write the png image to a binary connection. Does R support this?

Bob Albright
  • 2,242
  • 2
  • 25
  • 32

3 Answers3

2

No, the graphics devices are file-based, so your steps 1-3 are correct. You need a fourth to unlink the temporary file but that is about it.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks the answer, Dirk. Too bad it's all file based. – Bob Albright Jan 12 '10 at 03:20
  • Indeed -- requests for extending the 'connection' interface have been voiced on r-devel, but alas to no effect yet. As we can't expect R Core to code this, fleshing out an interface would be a first step. You have the source, so if the itch really needs scratching ... ;-) – Dirk Eddelbuettel Jan 12 '10 at 03:39
2

If you use either lattice or ggplot, you can save the plot object (rather than the image itself) to the database (although I don't know if that meets your requirement). The benefit of that approach is that you can easily recreate/alter the image.

Shane
  • 98,550
  • 35
  • 224
  • 217
0

Instead of writing to a regular file, could you write it to a FIFO that would in turn store it in the DB? Will graphics devices write to a FIFO if it's created externally?

Ken Williams
  • 22,756
  • 10
  • 85
  • 147