[Rd] data.frame within a function (PR#9294)

rcheng at purdue.edu
Thu, 12 Oct 2006 17:45:24 -0000

Full_Name: Riyan Cheng
Version: windows 2.0.1
OS: windows xp
Submission from: (NULL) (74.140.105.186)



If one runs the following function ff(), an error would occur regarding
data.frame():
  ff<- function(){
     x<- rnorm(10)
     y<- rnorm(10)
     lm1<- lm(y~1,data=data.frame(y=y,x=x)); cat("ok\n")
     update(lm1,~ .+x,evaluate=T); cat("also ok\n")
     add1(lm1, ~ .+x);  cat("again ok\n")
  }
  ff()
But if there are external variables y and x, one would not get correct results.
This problem does not exist if one directly runs the body of the function:
  x<- rnorm(10)
  y<- rnorm(10)
  lm1<- lm(y~1,data=data.frame(y=y,x=x)); cat("ok\n")
  update(lm1,~ .+x,evaluate=T); cat("also ok\n")
  add1(lm1, ~ .+x);  cat("again ok\n")

There is exactly the same problem in Unix version.