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

rcheng at purdue.edu rcheng at purdue.edu
Thu Oct 12 19:45:24 CEST 2006


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.




More information about the R-devel mailing list