[Taken off R-bugs, at least for now.]

On Thu, 17 Apr 2008, Peter Dalgaard wrote:

[EMAIL PROTECTED] wrote:
I think we should allow only all-zero arguments (at present any
zero-length argument is an error), as per the R-level proposed code.

arrows() and rect() share the code so it is much cleaner to do this
internally.


There are precedents for not requiring all-or-none zero-length args. In
arithmetic, "recycling" treats the case of one zero length item as if
all had length zero

2+numeric(0)
numeric(0)

There are also rules for array arithmetic.

cbind() and rbind() are a bit anomalous in that they just throw away the
offending item:

cbind(a=1:2,b=numeric(0),c=3:4)
    a c
[1,] 1 3
[2,] 2 4

Only the former variant would make sense for segments(), but segments()
does recycle, unlike lines() which complains if vectors are of different
length.

And neither is documented. Also S has changed its recycling rules in various ways over its lifetime.

I think there are cases where you might want it to just do nothing
rather than warn and do nothing or cause an error. Consider rug()-like code:
segments(x, ytop, x, ybot) with an empty x. (I realize that the real
rug() uses Axis(), but the point remains.)

I agree it is moot, which is why I commented on this. Rich's proposal was the one I ended up implementing, but it was not my first idea. There are also cases when you pass zero-length arguments in error, and I thought those more likely.


Done for R-devel.

On Thu, 17 Apr 2008, [EMAIL PROTECTED] wrote:


Uwe Ligges suggested I post this on R-bugs as a wishlist item with a
proposed patch.  R considers zero-length arguments to segments() to be
an error.  I would like R to allow this and to return without an
error.  It occurs naturally in settings like

valid <- c(FALSE, FALSE, FALSE)
segments(x0[valid], y0[valid], x1[valid], y1[valid])

For what it may be worth, S-Plus does not consider zero-length
arguments to segments() be an error.


plot(1:10)
segments(1,1,10,10,col='green')
segments(numeric(0), numeric(0), numeric(0), numeric(0), col='green')
Error in segments(x0, y0, x1, y1, col = col, lty = lty, lwd = lwd, ...) :
       invalid first argument


segments.proposal <-
 function (x0, y0, x1, y1, col = par("fg"), lty = par("lty"),
           lwd = par("lwd"), ...) {
   if (length(x0)==0 && length(y0)==0 && length(x1)==0 && length(y1)==0)
     return(invisible(NULL))
   .Internal(segments(x0, y0, x1, y1, col = col, lty = lty, lwd = lwd, ...))
}

segments.proposal(numeric(0), numeric(0), numeric(0), numeric(0), col='green')

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel






--
  O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])              FAX: (+45) 35327907




--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to