Description Usage Arguments Details Examples
Experimental helper function for reading text data sequentially from a file on disk and adding to connection using addData
1 2 3 |
input |
the path to an input text file |
output |
an output connection such as those created with |
overwrite |
logical; should existing output location be overwritten? (also can specify |
linesPerBlock |
how many lines at a time to read |
fn |
function to be applied to each chunk of lines (see details) |
header |
does the file have a header |
skip |
number of lines to skip before reading |
recordEndRegex |
an optional regular expression that finds lines in the text file that indicate the end of a record (for multi-line records) |
cl |
a "cluster" object to be used for parallel processing, created using |
The function fn
should have one argument, which should expect to receive a vector of strings, each element of which is a line in the file. It is also possible for fn
to take two arguments, in which case the second argument is the header line from the file (some parsing methods might need to know the header).
1 2 3 4 5 6 7 8 9 10 | csvFile <- file.path(tempdir(), "iris.csv")
write.csv(iris, file = csvFile, row.names = FALSE, quote = FALSE)
myoutput <- localDiskConn(file.path(tempdir(), "irisText"), autoYes = TRUE)
a <- readTextFileByChunk(csvFile,
output = myoutput, linesPerBlock = 10,
fn = function(x, header) {
colNames <- strsplit(header, ",")[[1]]
read.csv(textConnection(paste(x, collapse = "\n")), col.names = colNames, header = FALSE)
})
a[[1]]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.