I wrote a parser for this kind of thing yesterday, but it was for a very specific kind of input to the header file, so I will show you how to format your column widths to be able to use it.
You can download the binary from the bin directory if you are on OS X Mavericks (where I compiled it on) or compile it by going to src and using clang++ csv_iterator.cpp parse.cpp main.cpp -o flatfileparser.
The flat file parser needs two files, a CSV header file in which every fifth element specifies the variable width (again, this is due to my extremely specific application), which you can generate using:
cols = c(8,10,1,2,1,1,1,3,4,3,2,2,4,4,1,4,1,4,1,1,1,1,3,2,2,1,2,2,13,2,4,1,1,1,1,3,3,3,2,3,3,3,3,3,3,3,2,2,2,2,1,1,1,1,1,6,6,6,2,1,1,2,1,1,1,1,1,2,2,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,7,5,4,10,3,3,2,2,2,3,1,1,1,1,2,2,1,1,2,1,9,5,5,1,1,1,2,2,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,1,4,1,4,1,1,3,3,3,3,2,2,2,2)
writeLines(sapply(c(-1, cols), function(x) paste0(',,,,', x)), '~/tmp/header.csv')
and copying the resulting ~/tmp/header.csv to the same directory as your flatfileparser. Move the flat file to the same directory as well, and you can run it on your flat file:
./flatfileparser header.csv yourflatfile
which will produce yourflatfile.csv. Add the header you have above in manually using piping (>> from Bash).
Use Hadley's experimental fastread package by passing the filename to fastread::read_csv, which yields a data.frame. I don't believe he supports fwf files yet although it is on the way.
mark-mbp-osx:bin mark$ flatfileparser header.csv COLRECT.TXT
-bash: flatfileparser: command not found
mark-mbp-osx:bin mark$ ls COLRECT.TXT flatfileparser header.csv
chmod +x flatfileparser; ./flatfileparser header.csv COLRECT.TXT
mark-mbp-osx:bin mark$ chmod +x flatfileparserchmod +x flatfileparser; ./flatfileparser header.csv COLRECT.TXT
chmod: flatfileparserchmod: No such file or directory
chmod: +x: No such file or directory
I think you pasted the string "chmod +x flatfileparser" twice. Try two separate commands: first chmod +x flatfileparser and then ./flatfileparser header.csv COLRECT.TXT
My fault, I pasted it into SO twice. I ended up with 144 columns instead of 143. It seems to work fine, so thanks. I am not sure I could use this regularly or on our Windows server. It would be great if it were easy to access from within R. I am just not a real programmer.