Learn R Programming

HadoopStreaming (version 0.1)

hsKeyValReader: Reads key value pairs

Description

Uses scan to read in chunkSize lines at a time, where each line consists of a key string and a value string. The first skip lines of input are skipped. Each group of key/value pairs are passed to FUN as a character vector of keys and character vector of values.

Usage

hsKeyValReader(file = "", chunkSize = -1, skip = 0, sep = "",FUN = function(k, v) cat(paste(k, v, sep = ": "), sep = ""))file{A connection object or a character string, as in scan.}
  chunkSize{The (maximal) number of lines to read at a
  time. The default is -1, which specifies that the whole file should be read at once.}
  skip{Number of lines to ignore at the beginning of the file}
  FUN{A function that takes a character vector as input}
  sep{The character separating the key and the value strings.}
No return value.
[object Object]
printFn <- function(k,v) {
    cat('A chunk:')
    cat(paste(k,v,sep=': '),sep='')
  str <- "key1"
  cat(str)
  con <- textConnection(str, open = "r")
  hsKeyValReader(con,chunkSize=2,FUN=printFn)
  close(con)
  con <- textConnection(str, open = "r")
  hsKeyValReader(con,FUN=printFn)
  close(con)

Arguments