With the suggestion of Jim Holtman I have successfully implemented the loop containing locator() using RGUI by toggling the buffer to OFF. However, I am using JavaGD and the loop still will not work so the Java graphics window is apparently buffered and I can't figure out how to turn it off. I really like Java JGR and its JavaGD. I haven't been able to get  the info from www.rosuda.org so if anyone has solved this buffer problem with JavaGD I would appreciate a note.

  ----- Original Message ----- 
  From: jim holtman 
  To: Bob Meglen 
  Cc: r-help@r-project.org 
  Sent: Sunday, May 24, 2009 5:06 PM
  Subject: Re: [R] Timing issue using locator() in loop containing print()


  Is the output buffered on the RGUI?  If so, uncheck it and see if the problem clears up.


  On Sun, May 24, 2009 at 3:24 PM, Bob Meglen <bmeglen@comcast.net> wrote:

    I am attempting to use locator(n=2) to select the corners of several (5 in this case) rectangles on an image displayed in a JavaGD window. The returned coords are used to draw labeled rectangles around the selected region.  I have tried several things to get this to work including sys.Sleep to correct what appears to be a timing issue with this loop. The first-time print in the loop doesn't print before locator executes several mouse clicks, and the order of  pt(1) and pt(2) in each execution of the loop gets out of sync. Please offer a suggestion.

    I am using Windows, Java Gui for R1.6-3,  R version 2.8.1.

    Example:

    #..........................................................PLOT the Image in Java Window.........................................................................
    JavaGD(name="JavaGD", width=640, height=480)
    #.........................................suppress margins all around.........................
    par(mar=c(0,0,0,0))
    image(xraw,col=my.grays(256),axes=F)
    #....................................Set up loop..........................................................................................................
    tot_subsets<-5
    ss<- matrix(0,nrow=tot_subsets,ncol=4)
    print("begin selections")
    # .........................Loop for multiple rectangle selections on image.....................................................
    for (i in 1:tot_subsets) {
    print("Select lower left and upper right for this rectangle")

                    sub_0<- locator(n=2)

        rect(sub_0$x[1],sub_0$y[1],sub_0$x[2],sub_0$y[2],col="red",density=0)
        text(sub_0$x[1]+(sub_0$x[2]-sub_0$x[1])/2,sub_0$y[1]+(sub_0$y[2]-sub_0$y[1])/2,paste("S",i),col="red")
    #.......................Add each reactangle coords to master subset list.................................................
                            ss[i,1]<-sub_0$x[1]
                            ss[i,2]<-sub_0$y[1]
                            ss[i,3]<-sub_0$x[2]
                            ss[i,4]<-sub_0$y[2]
    }
    print("finished selection")



    Thanks,
    Bob Meglen
    Boulder, CO

    ______________________________________________
    R-help@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.





  -- 
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390

  What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]


