[datatable-help] fread with multi-line character vector input
Douglas Clark
clark9876 at airquality.dk
Thu Oct 29 00:05:41 CET 2015
Can fread read from a multi-line character vector, similar to the read.table
text= argument? Feature request?
I am importing the output "print" file from a dispersion model (a fortran
program). The output file consists of 4000+ lines of text, tables of model
parameters, and tables of model results, all of varying lengths. I read the
entire file into a character vector variable, such as mylines <-
readLines(...), and then use regular expressions to "clean" the text and
locate the starting and ending lines of the tables to be imported.
I tried to use fread(mylines[start:stop]), but fread doesn't accept a vector
of character strings as input -- only a length 1 character vector (ie all in
one string).
read.table does allow reading from a multi-line character vector variable,
using the text= argument, ie read.table(text = mylines[start:stop],...).
fread will also read it, if I collapse the multi-line character vector into
a single string using paste0 or stri_flatten, as in
fread(paste0(mylines[start:stop], collapse = "\n"))
or
fread(stri_flatten(mylines[start:stop], collapse = "\n"))
But it would be nice if I could skip the collapse step.
Does fread have a way to directly read from a multi-line character vector
without flattening it -- like the text= argument in read.table ? Or is
there an easier approach? If not, should this be a feature request?
--
View this message in context: http://r.789695.n4.nabble.com/fread-with-multi-line-character-vector-input-tp4714096.html
Sent from the datatable-help mailing list archive at Nabble.com.
More information about the datatable-help
mailing list