Skip to content

Instantly share code, notes, and snippets.

@jwijffels
Created March 25, 2013 18:00
Show Gist options
  • Save jwijffels/5239198 to your computer and use it in GitHub Desktop.
Save jwijffels/5239198 to your computer and use it in GitHub Desktop.
S3 methods for streaming modelling with R package stream and for data in an ffdf
DSD_FFDFstream <- function(x, k=NA, assignment=NULL, loop=FALSE) {
stopifnot(is.ffdf(x))
open(x)
state <- new.env()
assign("counter", 1L, envir = state)
l <- list(description = "FF Data Stream",
strm = x,
state = state,
d = ncol(x),
k = k,
assignment = assignment,
loop = loop)
class(l) <- c("DSD_FFDFstream","DSD_R","DSD")
l
}
get_points.DSD_FFDFstream <- function(x, ...){
stream:::get_points.DSD_Wrapper(x, ...)
}
print.DSD_FFDFstream <- function(x, ...) {
NextMethod() # calling the super classes print()
pos <- x$state$counter
if (pos>nrow(x$strm))
if (!x$loop) pos <- "'end'" else pos <- 1
cat(paste('Contains', nrow(x$strm),
'data points - currently at position', pos,
'- loop is', x$loop, '\n'))
}
reset_stream.DSD_FFDFstream <- function(dsd) {
stream:::reset_stream.DSD_Wrapper(dsd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment