From bolker at zoo.ufl.edu  Mon Nov 13 14:31:13 2006
From: bolker at zoo.ufl.edu (Ben Bolker)
Date: Mon, 13 Nov 2006 08:31:13 -0500
Subject: [Rd] bug in lrect [lattice]?
Message-ID: <455873A1.4060809@zoo.ufl.edu>


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)



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20061113/4fcfeb6c/attachment.bin 


[Rd] bug in lrect [lattice]?
Ben Bolker