Skip to content
Prev 18201 / 63424 Next

read.fwf doesn't work with header = TRUE (PR#8226)

Prof Brian Ripley wrote:
I see, but suppose we read selectively some columns in a file, eg with 
widths=c(1, -4, 2), how can we know how many variables have been skipped 
and then select the appropriate names in the header line?

Here is another proposed fix, but this assumes the header line is in 
fixed-width format (as specified by 'widths'):

38c38,41
<         cat(FILE, headerline, "\n")
---
 >         head.last <- cumsum(widths)
 >         head.first <- head.last - widths + 1
 >         headerline <- substring(headerline, head.first, head.last)[drop]
 >         cat(file = FILE, headerline, "\n", sep = sep)

?read.fwf says clearly that sep is used internally.