How to save R plot image to database?

穿精又带淫゛_ 提交于 2019-12-24 00:54:10

问题


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?


回答1:


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.




回答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.




回答3:


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?



来源:https://stackoverflow.com/questions/2045837/how-to-save-r-plot-image-to-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!