[Rd] bug in lrect [lattice]?

From: Ben Bolker <bolker_at_zoo.ufl.edu>
Date: Mon 13 Nov 2006 - 13:31:13 GMT

In lattice version 0.14-11 (2006/10/23), there appears to be a small bug in lrect [lattice]: border is set to NULL accidentally. It is easily fixed by adding one line to lrect -- see example and hack below ...

  I wasn't sure if this should be submitted as an R bug since it is part of a package, but a core/recommended package ...

  Ben Bolker

x = runif(100)
y = runif(100)

my.lrect <- function (xleft, ybottom, xright, ytop, x = (xleft + xright)/2,

    y = (ybottom + ytop)/2, width = xright - xleft, height = ytop -

        ybottom, col = "transparent", border = "black", lty = 1,     lwd = 1, alpha = 1, just = "center", hjust = NULL, vjust = NULL,     ...)
{
  if (missing(border)) ## this line fixes it     border <- if (all(is.na(border)))
      "transparent"
    else if (is.logical(border)) {

      if (border)
        "black"
      else "transparent"

    }
  grid:::grid.rect(x = x, y = y, width = width, height = height, default.units = "native",

        just = just, hjust = hjust, vjust = vjust, gp = grid:::gpar(fill = col,

            col = border, lty = lty, lwd = lwd, alpha = alpha,
                                                     ...))

}

ranrect <- function(s,fun=lrect) {
  coords <- runif(2,s/2,1-s/2)
  fun(coords[1]-s/2,coords[2]-s/2,coords[1]+s/2,coords[2]+s/2,

        border="red",lwd=2)
}

library(lattice)
## with original lrect: border is black rather than red xyplot(y~x,

       panel=function(...) {
         panel.xyplot(...)
         ranrect(s=0.12)
       })

## new lrect: works
xyplot(y~x,

       panel=function(...) {
         panel.xyplot(...)
         ranrect(s=0.12,fun=my.lrect)
       })

 version
               _
platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status
major          2
minor          4.0
year           2006
month          10
day            03
svn rev        39566
language       R

version.string R version 2.4.0 (2006-10-03)



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Nov 14 06:55:52 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 14 Nov 2006 - 13:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.