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
Luke, On 24 October 2007 at 15:16, Luke Spadavecchia wrote: | 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 Your questions is essentially FAQ 7.19. In non-interactive mode, R simply has no X11 device. You need xvfb or other solutions. A relatively new option is the Cairo device which IIRC does not need X11 and a display variable. | 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. There are other options, including embedding R or running Rserve, but they are all little more involved. Cheers, Dirk -- Three out of two people have difficulties with fractions.
Not sure about answering your original question, but why not write the graphics output to a file, then fire up a viewer? David Scott On Wed, 24 Oct 2007, Luke Spadavecchia wrote:> 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 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >_________________________________________________________________ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics Director of Consulting, Department of Statistics
Hi Dirk, Thanks for your useful advice, although I am not sure I fully understand your response. I am able to open x11 windows from R CMD BATCH both in windows XP,MAC OS X and Linux (on various machines I use), providing the relevant Sys.setenv() commands are in the script I call prior to plotting commands. My problem is that the X11 windows only persist as long as the script is running, and disappear when R exits - which is very rapid for most plots (it is only when the script imports a shapefile using maptools or something like that that the window is open long enough to really examine the plot). Is there a way when running R (from batch mode or otherwise) of 'saving' X11 windows, and keeping them open after the R session is complete? I don't really want to write the graphics to file, because the repeated calls from the Fortran code would overwrite each other, and the idea is to do rapid appraisal of the simulated annealing schedule, to check that mixing/cooling are progressing in an efficient and useful manner. Would using cairo (which I can't seem to get to work at the moment) allow me to do this? I'm not sure it's an x11 problem, but rather something to do with the way that R and X11 communicate? Many thanks Luke Spadavecchia
I had this same issue. My quick and dirty solution was to create an infinite loop at the end of my R plotting script and then manually kill the job with Ctrl+C once I was done looking at the plot. -- View this message in context: http://r.789695.n4.nabble.com/X11-graphics-windows-under-CMD-BATCH-tp838015p3335922.html Sent from the R help mailing list archive at Nabble.com.