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

Dirk Eddelbuettel edd at debian.org
Wed Jun 4 20:38:37 CEST 2008



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)
| dev.off()
|  
| 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.

Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-help mailing list