[R] File Reading Problem

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Sep 1 20:47:48 CEST 2003

?readBin  will do what you want.  If the file is really a set of lines, 
you could use readLines() followed by strsplit().

See also the R Data Import/Export manual.

On Mon, 1 Sep 2003, Jiming Yu wrote:

> Dear all,
>     I am trying to read characters byte by byte(in their ASCII codes) from a
> file(already transferred from text file to a file of ASCII codes, by C
> language). I am using scan() function. But it seems that this is impossible.
>     If I read data as 'character' type, data are read word by word,
> separated by spaces(though in default setting, sep=""). e.g. if a file
> contains "This is a book.", Then it reads "This", "is", "a", "book.", not
> "T", "h", "i", "s", etc(as I wanted it to).
>     If I read data as 'integer' type from the file which contains all ASCII
> codes of the original file, e.g. if a file contains "This is a book.", Then
> it reads "T", " ", "i", " ", "a", " " , "b", which are initials of all words
> and all spaces, not "T", "h", "i", "s", etc(as I wanted it to).
>     If anybody has a solution, please let me know. I'd really appreciate
> your help. Thank you very much!

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