Re: [R] [Rd] An issue happens Embed R and redirt png file

From: Dirk Eddelbuettel <>
Date: Wed, 04 Jun 2008 13:38:37 -0500

Wrong list, so re-directing to r-help. Consider r-sig-debian for Debian questions too, but subscribe or else your posts bounce.

On 4 June 2008 at 07:18, Rongrong wrote:
| I am a new R user and I have a question of embedding R to generate png
| On Debian, I installed R by source code.
| Now I want to embed R in an application which name is MyApp, and run
| the following syntax:
| png(filename="/tmp/Rplot%03d.png)
| example(rect)
| Unfortunately I get the following error message:
| Error in X11(paste("png::", filename, sep = ""), width, height, pointsize,
| :
| unable to start device PNG
| Calls: png
| In addition: Warning message:
| In png(filename = "/tmp/test%03d.png") :
| unable to open connection to X11 display ''

See the R FAQ.  

| But I could run above syntax from R, and the result is correct, I can get
| two png files from /tmp/ folder.
| I try to respectively run same syntax(the syntax is:
| capabilities()[["png"]])
| under two modes, the result is different:
| In R the result is TRUE, but when MyApp embed R the result is FALSE

Because in case you have an x11 display, and in the other your don't. No display, no x11.  

| Then I used bitmap(file="/tmp/test") when embed R in MyApp, but get another
| error message:
| Error in bitmap(file = "/tmp/test") : sorry, 'gs' cannot be found

Fix that via

    $ sudo apt-get install ghostscript  

| Besides, I have installed xvfb. What I need do?

Almost there. Wrap your call to MyApp in svfb-run, ie do

    $ xvfb-run MyApp [other parameters]

and you get the virtual x11 device that png needs.

R 2.7.0 should also alleviate the need for an x11 device due to its new cairo-based device code. While you didn't tell as which R version you are running, I suspect it is not the one the current one.


Three out of two people have difficulties with fractions.

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 04 Jun 2008 - 19:43:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 Jun 2008 - 08:30:39 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive