How to run R on a server without X11, and avoid broken dependencies
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.
How to run R scripts on servers without X11
I answered this once before -- can cannot make a program which expects X11 to certainly forget about it, but you can use the virtual framebuffer to 'pretend' X11 is present.
So see this older SO question for details and an example.
Compile R with Cairo support without X11
In the most narrow sense, Cairo appears to require x11 headers.
In a wider sense, look into the various answers detailing use of the xvfb
virtual x11 server -- they allow you headless use.
Also, you could try building without x11, png, cairo -- and then use one of the two cairo packages from CRAN to create graphs. In Debian/Ubuntu we also have at least the cairoDevice package pre-build for you.
generate png with R
Found the answer to my own question thanks to comments from @Spacedman
Turned out I still needed to install the 'libpango1.0-dev' package. "capabilities('X11');" still gives FALSE but "png();" no longer gives errors, so my problem is fixed. Thank you for pointing me in the right direction!
Alias function name in .Rprofile so that it is used by all R Scripts
Add a message
statement so when R starts we can verify that the .Rprofile did, in fact, run. Also use library
instead of require
because library
will give an error right at that point if it fails making it easier to debug. Then instead of putting png in the global environment insert it into the grDevices namespace. To do that it must be unlocked first.
# This code goes in .Rprofile file
message("Hello")
library("Cairo")
unlockBinding("png", asNamespace("grDevices"))
utils::assignInNamespace("png", CairoPNG, "grDevices")
For a different approach check out:
How to run R on a server without X11, and avoid broken dependencies
How to run R on a server without X11, and avoid broken dependencies
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.
Related Topics
Read.Csv, Header on First Line, Skip Second Line
Reduce PDF File Size of Plots by Filtering Hidden Objects
Changing Whisker Definition in Geom_Boxplot
Split Date into Different Columns for Year, Month and Day
How to Add Table of Contents in Rmarkdown
Generate Random Numbers with Fixed Mean and Sd
How to Use the Strsplit Function with a Period
Building R Package and Error "Ld: Cannot Find -Lgfortran"
Define $ Right Parameter with a Variable in R
Non-Equi Join Using Data.Table: Column Missing from the Output
Min for Each Row in a Data Frame
Is There a Better Alternative Than String Manipulation to Programmatically Build Formulas