R/nchunks.r

Defines functions nchunks.disk.frame nchunk.disk.frame nchunk nchunks

Documented in nchunk nchunk.disk.frame nchunks nchunks.disk.frame

#' Returns the number of chunks in a disk.frame
#' @param df a disk.frame
#' @param skip.ready.check NOT implemented
#' @param ... not used
#' @export
#' @examples
#' cars.df = as.disk.frame(cars)
#' 
#' # return the number of chunks
#' nchunks(cars.df)
#' nchunk(cars.df)
#' 
#' # clean up cars.df
#' delete(cars.df)
nchunks <- function(df, ...) {
  UseMethod("nchunks")
}


#' @rdname nchunks
#' @export
nchunk <- function(df, ...) {
  UseMethod("nchunk")
}

#' @rdname nchunks
#' @export
nchunk.disk.frame <- function(df, ...) {
  nchunks.disk.frame(df, ...)
}

#' @importFrom fs dir_ls
#' @rdname nchunks
#' @export
nchunks.disk.frame <- function(df, skip.ready.check = FALSE, ...) {
  fpath <- attr(df,"path", exact=TRUE)
  if(is.dir.disk.frame(df)) {
    return(length(list.files(fpath, pattern="fst", recursive = TRUE)))
  } else {
    return(1)
  }
}

Try the disk.frame package in your browser

Any scripts or data that you put into this service are public.

disk.frame documentation built on Aug. 24, 2023, 5:09 p.m.