[R] Scope change in R1.2?

Robert Gentleman rgentlem at jimmy.harvard.edu
Mon Dec 18 15:30:50 CET 2000


Indeed there have been some changes to the way in which formulas
resolve the symbols they contain. We hope that overall it will be for
the better but there are some situations where things need to change.

First let me explain why we changed things.
Suppose that I have the following:

x<- somedata
y<- someotherdata
form<-y~x

here I have a clear idea that the y and x in my formula are
 the y and x I have defined
but under the old system there was no way to ensure that


foo<-function(form) {
  x <- 1
  y <-2
  model.frame(form)
}

a call to foo in the old system would cause me to pick up
the local values of x and y -- 1 and 2, not my original
data.

you are in the situation, I think, where you want the local x and y
to do that I would change the function foo to:
foo<-function(form) {
  x <- 1
  y <-2
  model.frame(form, data=environment())
}

Which asks form to first look in the environment or data frame
specified by data argument. As the help file says, the second place to
look is the environment associated with the formula (lexical scope,
sort of). We no longer search the top-level environment (or any other
environment) for unresolved symbols.

The goal is to ensure more robust modeling although I'm sure the
impact on some will be a bit of frustration.
You didn't provide enough code for me to tell you how to fix your
particular problem, but if these hints aren't enough please send me a
more complete version of your code and I'll give you some concrete
suggestions. 

  Robert

-- 
+---------------------------------------------------------------------------+
| Robert Gentleman                 phone : (617) 632-5250                   |
| Associate Professor              fax:   (617)  632-2444                   |
| Department of Biostatistics      office: not yet                          |
| Harvard School of Public Health  email: rgentlem at jimmy.dfci.harvard.edu   |
+---------------------------------------------------------------------------+
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list