[英]R unable to start device PNG - capabilities() has TRUE for PNG?
I am working with a R script within a wider pipeline that seems to not work with some versions of Rscript but with others. 我正在更广泛的管道中使用R脚本,似乎不适用于某些版本的Rscript但与其他版本一起使用。 The call fails due to being unable to connect to X11, which is understandable because this is on a server.
由于无法连接到X11,调用失败,这是可以理解的,因为这是在服务器上。 But my local installation of Rscript is able to handle this fine?
但我在本地安装Rscript能够处理这个问题吗?
My local installation is version 3.0.1, while the one that other users that are reporting this problem are on 3.0.2. 我的本地安装是版本3.0.1,而报告此问题的其他用户的版本是3.0.2。
Here is a simple test case - first the .R file: 这是一个简单的测试用例 - 首先是.R文件:
#!/usr/bin/env Rscript
capabilities()
png("abc")
dev.off()
Run with my local env: 用我的本地环境运行:
-bash-4.1$ ./test.R
jpeg png tiff tcltk X11 aqua http/ftp sockets
TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE
libxml fifo cledit iconv NLS profmem cairo
TRUE TRUE FALSE TRUE TRUE FALSE TRUE
null device
1
Run on the installation of Rscript others are trying to use: 运行Rscript的安装其他人正在尝试使用:
jpeg png tiff tcltk X11 aqua http/ftp sockets
TRUE TRUE FALSE TRUE FALSE FALSE TRUE TRUE
libxml fifo cledit iconv NLS profmem cairo
TRUE TRUE FALSE TRUE TRUE FALSE TRUE
Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, :
unable to start device PNG
Calls: png
In addition: Warning message:
In png("abc") : unable to open connection to X11 display ''
Execution halted
万一有人在谷歌上找到这个,解决方案是
png("abc", type="cairo")
You can run it in the R command 您可以在R命令中运行它
options(bitmapType='cairo')
png("xzvf.png")
plot(z~x)
dev.off()
Try prefixing the call to Rscript
with 尝试使用前缀来调用
Rscript
xvfb-run
or even 甚至
xvfb-run --server-args="-screen 0 1024x768x24"
as png, if memory serves, uses x11 font information. 如png,如果内存服务,则使用x11字体信息。 The virtual x11 server started by
xvfb-run
provides it, so it helps in headless settings, cron jobs, etc pp 由
xvfb-run
启动的虚拟x11服务器提供它,因此它有助于无头设置,cron作业等pp
I had the same issue on fresh install of Ubuntu 14.04. 我在新安装的Ubuntu 14.04上遇到了同样的问题。
Simply installing xvfb-run
solved the issue, even without running it before launching R. 简单地安装
xvfb-run
解决了这个问题,即使在启动R之前没有运行它也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.