How to run R on a server without X11, and avoid broken dependencies

て烟熏妆下的殇ゞ 提交于 2019-12-11 10:23:37

问题


I'm running R 2.9 on a large EC2 Ubuntu instance, loaded with RAM, but without a terminal. When I load a library that has display dependencies, such as the sqldf package, I receive the following error:

library(sqldf)
...
Loading required package: tcltk
Loading Tcl/Tk interface ... Error in fun(...) : couldn't connect to display "localhost:11.0"
Error : .onLoad failed in 'loadNamespace' for 'tcltk'
Error: package 'tcltk' could not be loaded

This seems to be a general problem, and I'm wondering how others have solved it. Installing an X11 server is not a desirable solution.


回答1:


Use the virtual framebuffer X11 server -- we do the same to build packages requiring X11 for R builds in headless chroots. Taking e.g. pars of the Build-Depends from rggobi:

xvfb xauth xfonts-base

After installing these you can use the xvfb-run command. If you start R via e.g.

xvfb-run R --no-save

you should now be able to use routines and commands requiring X11 as e.g. some of the plotting devices, or the tcl/tk initialization which also insists on having X11.

The same trick is useful for web servers.




回答2:


Dirk's suggestion indeed works well, if you have control over the server & can run xvfb. If not, read on...

in newer versions of R (>= 2.10 & maybe earlier), this is no longer an error, it's a warning:

> library(tcltk)
Loading Tcl/Tk interface ... done
Warning message:
In fun(libname, pkgname) : no DISPLAY variable so Tk is not available

You can now suppress this warning, and the subsequent package loading message via:

> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))

Often you will see this message due to loading a package like qvalue which depends on tcltk; if you're after silent operation, you should silently load tcltk first, then the package of interest:

> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
> library(qvalue)

Mark

resurrected due to: http://dev.list.galaxyproject.org/wrapping-qvalue-in-Galaxy-td4655164.html



来源:https://stackoverflow.com/questions/34277506/using-r-without-x11

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