简体   繁体   English

R无法启动设备PNG - 功能()对于PNG是否为TRUE?

[英]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.

相关问题 jupyter 中的 r 图形 - 无法启动 png() 设备 - r graphs in jupyter - unable to start png() device 错误:无法启动 png() 设备 - Error : Unable to start png() device R Shiny 运行几个小时后无法启动 png 设备 - R Shiny unable to start png device after running a few hours 绘制编织错误:“无法启动 png() 设备” - Plot knitting error : “unable to start png() device” R包编织程序无法打开png()设备 - R package knitr unable to open png() device 无法导出绘图:R 代码执行错误/无法启动 png() 设备 - Unable to export plot: R code execution error/ unable to start png() device R Markdown使用动态字符串扩展:无法启动png()设备时出现错误,没有明确的原因有时 - R Markdown Expanding with Dynamic String: Error unable to start png() device Shows Up Occasionally Without Clear Reason sp_execute_external_script R 脚本'无法启动 png() 设备' - sp_execute_external_script R script 'unable to start png() device' 无法启动 plot 名称的 png() 设备使用“粘贴”function 创建 - unable to start png() device for plot names create with "paste" function ggsave() 失败并在 png_dev(..., res = dpi, units = "in") 中出现错误:无法启动 png() 设备 - ggsave() fails with Error in png_dev(..., res = dpi, units = "in") : unable to start png() device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM