[R] X11 graphics windows under CMD BATCH

Luke Spadavecchia l.spadavecchia at googlemail.com
Wed Oct 24 16:16:14 CEST 2007


Hi there,

I am trying to plot some output from a  FORTRAN (ifort) program using  
R (2.5.1) under batch mode. In the FORTRAN code, I call R in batch  
mode to execute a script called fig1.R using something like

PROGRAM test
USE IFPORT
	IMPLICIT NONE

	DO
		!Some function which makes an output file called ~/fortran_output.txt
		CALL myfunc()

		!System call to R plotting routine
		CALL SYSTEM ("open -a x11")
		CALL SYSTEM ("R CMD BATCH ~/fig1.R")
	END DO

END PROGRAM test

The system call goes through fine, and R fires up and processes the  
contents of fig1.R which are something like:

Sys.setenv("DISPLAY"=":0.0")
Data<-read.table("~/fortran_output.txt")
x11(width=12)
plot(Data$var1,Data$var2)

My problem is that I want the x11 window which the plot appears in to  
persist after R exits; currently the figure flashes up momentarily,  
then disappears as R exits. One option is to try and stall the exit  
of R, by sticking a big loop at the end of the code, but this means  
my FORTRAN program is hanging about waiting for the loop to finish,  
and my plot still disappears. Is there any equivalent to -persist in  
GNUPLOT to allow the x11 window to stay open after R exits, so I can  
examine the results while the program continues?

To put all this in context, I want to examine the results of a  
simulated annealing process at each temperature reduction stage of  
the annealing schedule. I am not doing the annealing in R for reasons  
of speed: I only want to use R as a graphics engine.

Many thanks

Luke Spadavecchia



More information about the R-help mailing list