Skip to content

Display execution in a function

1 message · Sebastien Durand

#
Based on what Jim say yes it works, but if we 
look at the following function, which I beleive 
is properly written.

#############
area.select2<-function(nav,width=6,height=6,...){
	par(ask=TRUE)
	cat("Please select first two opposite 
corner of the working area","\n");
	plot(x=nav[,1],y=nav[,2],"l",col="blue");
	points=locator(2);
	ok<-0;
	while(ok!=1){
		cat("Is your selection correct: YES =1 or NO=0","\n");
		rect(xleft=min(points$x), 
ybottom=min(points$y), xright=max(points$x), 
ytop=max(points$y), density = 0,col = "red", 
border = TRUE);
		ok<-scan("",nlines=1,quiet=TRUE);
		if(ok!=1){
			cat("Please reselect your points","\n");
			points<-locator(2);
		}else{}
	}
	return(points);
}
#############

When run,  using the following call:
#############
area.select(nav=matrix(1:20,10,2))
#############

Even so the text output 'cat("Please reselect 
your points","\n")'  was written previously to 
'points<-locator(2)' , the text does not appears 
at the correct time when I try to select a new 
area.


I really don't understand what is going on there! 
Isn't suppose to be what is written first shall 
happen first!
Could this phenomenon be cause by the locator function...

Cheers!

S?bastien
...snip...