[R] Read from data frame, and not from global environment

Jochen Einbeck jochen.einbeck at nuigalway.ie
Tue Aug 2 12:57:49 CEST 2005


Dear members,

assume given  a function of type

test<-function(formula,  data , w){
  ......
  glm1<-glm(formula,  family=poisson, data=data, weights=w)
  ......
}

and a simple example data frame as

test.frame<-data.frame(x=1:10,y=(1:10)*2,a=(1:10)^3).

Let us now execute

test(y ~ x, test.frame, a )

My question is: What do I have to insert at the first occurance of ..... 
in the test function to ensure that

1) 'a'  is read from the data frame (and is only read from the global 
environment if  and only if  'a' is not found in the data frame)
2) glm finds w in in the local environment of the function 'test'

The question is obviously related to  Fernando's problem with   
'Defining a "local" function'  some months ago, though the discussion 
there does not solve the questions above.

Cheers,

Jochen Einbeck
NUI Galway, Ireland




More information about the R-help mailing list