[R] reading text file not table

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Feb 17 18:19:27 CET 2007


I think he is missing fill=TRUE, which is the default for read.csv but not
read.table.  (As Ted Harding implied but as I recall did not spell out.)

If you want to read a file as text, used readLines.  You can then extract 
the lines you want and use read.table on a textConnection from just those 
lines.

On Sat, 17 Feb 2007, Patrick Burns wrote:

> 'count.fields' is often useful in such situations to see how
> R's view of the file differs from your own.  (It isn't such
> a rare occurrence for differences to happen when the file
> comes from Excel.)
>
> If I understand properly, you can use
>
> sep='\n'
>
> as part of your alternative plan.  But I don't think you would
> need to write a file and read it back in again.
>
>
> Patrick Burns
> patrick at burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
>
> H. Paul Benton wrote:
>
>> Hello all,
>>
>> I'm looking for a way to be able to read a text file into R. It's a csv
>> file but when I do
>> "txt <-read.table("F00.csv", header=T, sep=",")" It doesn't read the
>> file properly, and I only get 2 columns. If I open it up in OOc or Excel
>> it open right with 7 columns.
>> What I would really like to do is read the file as text and then split
>> it and read the bottom section where the 7 columns are. Then I would
>> re-read the table with read.table.
>>
>>    Thank you for any help,
>>
>>    Paul
>>
>>
>>
>
> ______________________________________________
> R-help at 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list