Skip to content
Prev 74843 / 398502 Next

Read from data frame, and not from global environment

Thanks. It is now working as I wanted, if I use (simplified)

test<-function(formula, data, w){
  wname <- deparse(substitute(w))
  w <- if(wname %in% names(data)) data[[wname]] else get(wname, .GlobalEnv)
  data$w<-w
  glm1<-glm(formula=formula,data=data, weights=w)
  .....
}


What I was looking for in  2) was a more elegant way  (than setting 
data$w<-w)  to make  w  available to the glm function.
Prof Brian Ripley wrote: