R/odbc.R

Defines functions bigglm.RODBC

Documented in bigglm.RODBC

bigglm.RODBC<-function(formula, data, family = gaussian(),
                       tablename, ..., chunksize=5000){
  terms<-terms(formula)
  modelvars<-all.vars(formula)	
  dots<-as.list(substitute(list(...)))[-1]
  dotvars<-unlist(lapply(dots,all.vars))
  vars<-unique(c(modelvars,dotvars))
  query<-paste("select ",paste(vars,collapse=", ")," from ",tablename)
  result<-RODBC::odbcQuery(data, query)
  got<-0
  chunk<-function(reset=FALSE){
    if(reset){
      if(got>0){
        result<<-RODBC::odbcQuery(data,query)
        got<<-0
      }
      return(TRUE)
    }
    rval<-RODBC::sqlGetResults(data,max=chunksize)	
    got<<-got+NROW(rval)
    if (!is.data.frame(rval) || NROW(rval)==0) 
      return(NULL)
    return(rval)
  }
  rval<-bigglm(formula, data=chunk, family=family, ...)
  rval$call<-sys.call()
  rval$call[[1]]<-as.name(.Generic)
  rval
}

		
markpurver/biglmm documentation built on Aug. 22, 2020, 12:05 a.m.