Re: [R] read.fwf and header

From: Gregor Gorjanc <gregor.gorjanc_at_bfro.uni-lj.si>
Date: Tue 31 Oct 2006 - 09:56:52 GMT

Martin Maechler wrote:

>>>>>> "Gregor" == Gregor Gorjanc <gregor.gorjanc@bfro.uni-lj.si>
>>>>>>     on Mon, 30 Oct 2006 23:33:21 +0100 writes:

>
> Gregor> Daniel Nordlund wrote:
> >> Gregor,
> >>
> >> According to the help for read.fwf, sep needs to be set
> >> to a value that occurs only in the header record. I
> >> changed the spaces to commas in the header record of your
> >> example and used the following syntax and was able to
> >> read the file just fine.
> >>
> >> new.data<-read.fwf(file="test.txt", widths=c(3, 4, 10, 3,

> >> 2, 2, 2, 2, 11, 19), header=TRUE, sep=',')
> >>
> >> Hope this is helpful,
> >>
> >> Dan
>
> Gregor> Thanks Dan! But I have to modfy file first. Not that
> Gregor> much of work but still.
>
> Yes, but I think it shows read.fwf() should not be extended for
> even more special cases:
>
> In my (and probably R-core's) view, read.fwf() should only have
> to be used for ``legacy data files'' (those times when people used *no*
> separators in order to save disk space), since nowadays, such
> data files should "automatically" have correct separators.
>
> --> Fix the "file producing process" rather than make read.fwf()
> unnecessarily more complicated.

Thank you for this explanation of your (and probably R-core's) view! I really appreciate such feedback. I do agree that read.fwf is a bit archaic way to import data, but sometimes you can not fix "file producing process".

Perhaps above explanation and code examples from this thread could be added to read.fwf help page. I can provide a patch if my proposal is sane.

Regards, Gregor



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue Oct 31 21:04:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 31 Oct 2006 - 11:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.