From berwin at maths.uwa.edu.au  Tue Mar 29 05:53:56 2005
From: berwin at maths.uwa.edu.au (Berwin A Turlach)
Date: Tue Mar 29 05:54:26 2005
Subject: [Rd] improved pairs.formula?
Message-ID: <16968.53588.237010.198357@bossiaea.maths.uwa.edu.au>

Dear all,

I would like to suggest changing the pairs.formula command such that a
command like

        pairs(GNP ~ . - Year - GNP.deflator, longley)

would behave in a similar fashion as 

        lm(GNP ~ . - Year - GNP.deflator, longley)

i.e., make a pairwise scatterplot of GNP and all other variables in
the (longley) dataframe except for Year and GNP.deflator.  The above
command, with the current version of pairs.formula, produces a
pairwise scatterplot of all variables in the (longley) dataframe.

After some tinkering around, I came up with the following replacement
function of pairs.formula which seems to do the job:

    pairs.formula <- 
    function (formula, data = NULL, ..., subset, na.action = stats::na.pass) 
    {
      m <- match.call(expand.dots = FALSE)
      if (is.matrix(eval(m$data, parent.frame()))) 
        m$data <- as.data.frame(data)
      m$... <- NULL
      m$na.action <- stats::na.pass
      m[[1]] <- as.name("model.frame")
      mf <- eval(m, parent.frame())
    
      mt <- attr(mf, "terms")
      tmp <- attr(mt, "factors")
      ind <- apply(tmp, 1, max)
      sv <- rownames(tmp)[ind>0]
      ind <- match(sv,
                   sapply(attr(mt, "variables"), deparse, width.cutoff=500)[-1])
      if( (tt <- attr(mt, "response")) != 0 ){
        ind <- c(tt, ind)
      }
    
      pairs(mf[,ind], ...)
    }

Would you please kindly consider replacing the current pairs.formula
function (at the top of the file src/library/graphics/R/pairs.R) with
the above function?

Best wishes,

        Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)   
School of Mathematics and Statistics        +61 (8) 6488 3383 (self)      
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin@maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin


[Rd] improved pairs.formula?
Berwin A Turlach