[R] Timing issue using locator() in loop containing print()

jim holtman
Sun, 24 May 2009 23:06:20 -0000

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<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]]