From rmh at temple.edu  Tue Sep  5 05:13:39 2006
From: rmh at temple.edu (Richard M. Heiberger)
Date: Mon,  4 Sep 2006 23:13:39 -0400 (EDT)
Subject: [Rd] Two submitted packages
Message-ID: <20060904231339.BHG87597@po-d.temple.edu>

## This example runs in R 2.3.1 and does not run in R 2.4.1.  I am
## raising it here for two questions: one on how to debug functions
## inside a namespace, the other on how to control clipping.

tmp <- data.frame(x=1:5, y=1:5, a=factor(c(1,1,1,1,1), levels=1:4))
xyplot(y ~ x,
       data=tmp, ylim=c(1.5,4.5),
       panel=function(x,y, ...) {
         cpv <- current.viewport()
         cpv$clip <- "off"
         pushViewport(cpv)
         panel.xyplot(x, y, ...)
         popViewport()
       })

## R version 2.4.0 Under development (unstable) (2006-08-14 r38872)
## gives the error message
Error in grid.Call.graphics("L_setviewport", pvp, TRUE) : 
        LOGICAL() can only be applied to a 'logical', not a 'character'
>

## Question 1.  How do I place a trace() on grid.Call.graphics to make
## it stop and give me a traceback.  I tried many variations of the
## command
##    trace(grid:::grid.Call.graphics, exit=recover,
##          where=environment(grid:::grid.Call.graphics))
## None of them trapped the error and let me trace it.  What is the
## correct incantation?



## Question 2.  How do I control clipping from within a panel
## function?  In 2.3.1, both of the following statements run without
## error.  Neither of them turns clipping off.
##
## In 2.4.0, the "off" statement gives the error message above.  The
## FALSE statement runs without error, but it didn't turn clipping off.

xyplot(y ~ x | a,
       data=tmp, ylim=c(1.5,4.5),
       panel=function(x,y, ...) {
         cpv <- current.viewport()
         cpv$clip <- "off"
         pushViewport(cpv)
         panel.xyplot(x, y, ...)
         popViewport()
       },
       layout=c(2,2))

xyplot(y ~ x | a,
       data=tmp, ylim=c(1.5,4.5),
       panel=function(x,y, ...) {
         cpv <- current.viewport()
         cpv$clip <- FALSE
         pushViewport(cpv)
         panel.xyplot(x, y, ...)
         popViewport()
       },
       layout=c(2,2))


## ?viewport in 2.4.0 says
## clip
##
## One of "on", "inherit", or "off", indicating whether to clip to the
## extent of this viewport, inherit the clipping region from the
## parent viewport, or turn clipping off altogether. For
## back-compatibility, a logical value of TRUE corresponds to "on" and
## FALSE corresponds to "inherit".

## Notice that "off" is current and FALSE is back-compatible, and
## "off" is the value that causes the error.

## What is the correct way to turn off clipping?
## The way that I would like to use is something on the order of

xyplot(y ~ x | a,
       data=tmp, ylim=c(1.5,4.5),
       panel=function(x,y, ...) {
         panel.xyplot(x, y, ...,
                      par.settings = list(clip = list(panel = "off")))
       },
       layout=c(2,2))

## I believe par.settings is currently valid only in xyplot() and not
## valid in panel functions.  Is my understanding correct?  Can the
## behavior be changed?
##
## The following statement works correctly in both 2.3.1 and 2.4.0.
## This statement controls clipping for the entire xyplot, not just
## for the single statement within the panel function.

xyplot(y ~ x | a,
       data=tmp, ylim=c(1.5,4.5),
       par.settings = list(clip = list(panel = "off")),
       layout=c(2,2))




[Rd] Two submitted packages
Richard M. Heiberger