R/fwf2csv.R
fwf2csv.Rd
Uses awk to convert a fixed-width file to a CSV based on stacks of whitespace.
fwf2csv(infile, toDF = FALSE, ...)
infile | The input file. Can also be |
---|---|
toDF | Logical. Should the file be read in while we are at it? Defaults
to |
... | Other arguments to be passed to |
A vector or a data.frame
, depending on the value in toDF
.
Only tested on Linux.
http://stackoverflow.com/q/30868600/1270695
Ananda Mahto and Ed Morton.
myfile <- tempfile(fileext = ".txt") Lines <- c("aaa b b ccc 345", "ddd fgt f u 3456", "e r der der 5 674") cat(Lines, sep = "\n")#> aaa b b ccc 345 #> ddd fgt f u 3456 #> e r der der 5 674#> [1] "aaa,b b,ccc,345" "ddd,fgt,f u,3456" "e r,der,der,5 674"fwf2csv(myfile, TRUE, header = FALSE)#> V1 V2 V3 V4 #> 1 aaa b b ccc 345 #> 2 ddd fgt f u 3456 #> 3 e r der der 5 674