R/findWords1.R

#' list the words in a text file
#' @param pfn - a text file possibly with a path included.
#' @return A list of the words and their sequence number in the file
#' @export

findWords1 <- function(pfn = NULL) {
  # read in the words from the file, into a vector of mode character
  #Matloff p 92 (Modified)
 # pfn <- paste("../Data/", fn, sep = "")
  cat("pfn:  ",pfn)
  txt <- scan(pfn,"")
  tl <- length(txt)
  cat("The text file was read and there are ", tl, " words.\n")
  wl <- list()      # Create a list called wl with no elements
  for (i in 1:tl) {
    wrd <- txt[i]  # i-th word in input file
    wl[[wrd]] <- c(wl[[wrd]],i)
  }
  return(wl)
}
bjw649/testBW1 documentation built on May 12, 2019, 9:27 p.m.