locator(n=1) or (n=500) as S-plus ?

Ross Ihaka ihaka@stat.auckland.ac.nz
Thu, 28 Jan 1999 19:59:24 +1300 (NZDT)


Martin Maechler writes:
 > >>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch> writes:
 > 
 >     MM> There's a non-compatibility between R and S-plus with the default
 >     MM> argument of the locator() function.
 > 
 >     MM> R      has locator(n=1)
 >     MM> S-plus has locator(n=500, type="n", noclick=F)
 > 
 >     MM> S's default is ``better'' I think, insofar as it means in 99% of
 >     MM> the cases ``user clicks <left> as many times as wanted and then
 >     MM> clicks <right> to end''
 > 
 >     MM> Ross Ihaka and his grad students are working on improving this
 >     MM> interface, I believe, however, I'd propose to just change
 > 
 >     MM> the default of n=1 to n=500 (or another "large" integer in order to
 >     MM> not copy S exactly).
 > 
 > I got 0 feedback..
 > 
 > What about the following new  locator()
 > which additionally adds a   `msg' argument 
 > 
 > The old behavior is got  by
 > 	locator( *, msg="")  or  
 > 	locator(*, msg=NULL) 
 > 
 > locator <- function(n = 512, 
 >                     msg = "Click left to locate points;  right to end") 
 > {
 >     do.msg <- is.character(msg) && nchar(msg) > 0
 >     if(do.msg) cat(msg,": ",sep="")
 >     z <- .Internal(locator(n))# n <= 0 gives error
 >     if(do.msg) cat("\n")
 >     x <- z[[1]]
 >     y <- z[[2]]
 >     if((n <- z[[3]]) > 0) list(x=x[1:n], y=y[1:n]) 
 > }
 > 
 > 
 > ---
 > Would anyone not like the default of `msg' writing to the console?
 > I've often been startled by functions using locator() and not prompting
 > the user to do start clicking in the graphic window at all..
 > 
 > One could also use the new argument
 > 
 >  prompt =
 >    "Use the graphics window to locate points;\n click left to add, right to end"
 > 

Sorry Martin, I missed this earlier.  I've got altogether too many
balls which I'm trying to keep in the air at present.

You proposal looks fine.  Another option would be to allow unlimited
points to be identified, and resize the array inside the C locator
function if necessary, but "500" is simpler and would cover almost all
cases.

I'm not sure about the message though.  The Macintosh only has one
button on its mouse -- input is terminated by typing a keystroke on
the keyboard.  Another option would be to use a call to the device
driver to retrieve an appropriate message for the device, of at least
to hide it in the C code where we could use #ifdef to select the
appropriate message.

	Ross
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._