[Rd] should delete.response(response~predictor) return ~predictor?

William Dunlap wdunlap at tibco.com
Fri Sep 21 19:57:02 CEST 2012


Thomas,

I noticed the delete.response() just returns its input if the input
is not of class "terms".   Hence we get surprising (to me) results like

  > env <- new.env()
  > env # formulae have an environment, calls do not
  <environment: 0x3244788>
  > with(env, delete.response(y ~ x1 + x2)) # class "formula"
  y ~ x1 + x2
  <environment: 0x3244788>
  > with(env, delete.response(quote(y ~ x1 + x2))) # class "call" (to `~`)
  y ~ x1 + x2

Without reading the help file, I would have expected ~x1+x2, as in
  > with(env, formula(delete.response(terms(y ~ x1 + x2))))
  ~x1 + x2
  <environment: 0x3244788>

survey:::summary.svytable (ver. 3.28-2) seems to expect delete.response
to work on calls, as it calls delete.response() on the call object which is
the "formula" argument in the "call" attribute of its input.

> survey:::summary.svytable
function (object, statistic = c("F", "Chisq", "Wald", "adjWald",
    "lincom", "saddlepoint"), ...)
{
    statistic <- match.arg(statistic)
    call <- attr(object, "call")
    ff <- call$formula
    if (is.null(environment(ff)))
        env <- parent.frame()
    else env <- environment(ff)
    ff <- delete.response(ff)
    ...

(Perhaps it was intended to get a real formula or terms object here, as the
environment of a call is NULL, unless the user attached the  ".Environment"
attribute.)

If delete.response doesn't do anything with non-terms objects, should it
throw an error if it is given such a thing?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



More information about the R-devel mailing list