如何将R图图像保存到数据库?
我想将绘图图像直接保存到数据库中。
R 中最好的方法是:
- 将绘图图像(png)写入文件系统
- 读取写入的文件
- 通过查询(RODBC)将文件发送到数据库
理想情况下,我想将上面的步骤 1 和 2 结合起来只需将 png 图像写入二进制连接即可。 R支持这个吗?
I'd like to save a plot image directly to the database.
Is the best way in R to do this:
- Write the plot image (png) to the filesystem
- Read the file that was written
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,图形设备是基于文件的,因此您的步骤 1-3 是正确的。您需要第四个来取消临时文件的链接,但仅此而已。
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.
如果您使用lattice或ggplot,您可以将绘图对象(而不是图像本身)保存到数据库中(尽管我不知道这是否满足您的要求)。这种方法的好处是您可以轻松地重新创建/更改图像。
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.
您是否可以将其写入 FIFO,然后将其存储在数据库中,而不是写入常规文件?如果 FIFO 是外部创建的,图形设备是否会写入该 FIFO?
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?