[Rd] segments() with zero-length arguments (PR#11192)

rmh at temple.edu rmh at temple.edu
Thu Apr 17 00:30:12 CEST 2008


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')



More information about the R-devel mailing list