Colleagues
I have just encountered an interesting problem with readLines in R
2.7.0 in Windows Vista. I am trying to read a line that is created in
the following manner:
1. Intel Fortran (ifort) 10.1 creates two text files.
2. The OS concatenates these files with: copy FILE1 +FILE2 FILE3
From R, I execute: readLines("FILE3")
Only the first portion of the file (the original FILE1) is read - the
remainder is ignored and there is no error message.
When I open FILE3 with Notepad, it shows all the text; however,
between the material originating from FILE1 and FILE2, there is a
single character - a right-pointing arrow. When I open the file with
vi in Windows (installed under ssh), it shows ^Z. When I open the
file with a hex editor (after having moved the file to a Mac), it
shows that this character is 1A.
I can get around the problem by working with the files separately.
However, this is not optimal. Is there a work-around that enables me
to read this file (and ignore the offending character)?
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com
[[alternative HTML version deleted]]
Try the following:
f <- file("your file", "rb") # read in binary mode
input <- readLines(f)
close(f)
On Mon, Jun 9, 2008 at 7:02 PM, Dennis Fisher <fisher@plessthan.com>
wrote:
> Colleagues
>
> I have just encountered an interesting problem with readLines in R
> 2.7.0 in Windows Vista. I am trying to read a line that is created in
> the following manner:
> 1. Intel Fortran (ifort) 10.1 creates two text files.
> 2. The OS concatenates these files with: copy FILE1 +FILE2
> FILE3
> From R, I execute: readLines("FILE3")
> Only the first portion of the file (the original FILE1) is read - the
> remainder is ignored and there is no error message.
>
> When I open FILE3 with Notepad, it shows all the text; however,
> between the material originating from FILE1 and FILE2, there is a
> single character - a right-pointing arrow. When I open the file with
> vi in Windows (installed under ssh), it shows ^Z. When I open the
> file with a hex editor (after having moved the file to a Mac), it
> shows that this character is 1A.
>
> I can get around the problem by working with the files separately.
> However, this is not optimal. Is there a work-around that enables me
> to read this file (and ignore the offending character)?
>
> Dennis
>
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com <http://www.plessthan.com/>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
>
http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
[[alternative HTML version deleted]]
Dennis Fisher wrote:> > Colleagues > > I have just encountered an interesting problem with readLines in R > 2.7.0 in Windows Vista. I am trying to read a line that is created in > the following manner: > 1. Intel Fortran (ifort) 10.1 creates two text files. > 2. The OS concatenates these files with: copy FILE1 +FILE2 FILE3 > From R, I execute: readLines("FILE3") > Only the first portion of the file (the original FILE1) is read - the > remainder is ignored and there is no error message. > > When I open FILE3 with Notepad, it shows all the text; however, > between the material originating from FILE1 and FILE2, there is a > single character - a right-pointing arrow. When I open the file with > vi in Windows (installed under ssh), it shows ^Z. When I open the > file with a hex editor (after having moved the file to a Mac), it > shows that this character is 1A. >Use the /b (binary) option of the copy command copy /b file1+file2 file3 Then no Ctrl+Z be written to file3. This is a known but easily forgotten irritant of the copy command in windows and dos. Berend Hasselman -- View this message in context: http://www.nabble.com/readLines-fails-to-read-entire-file-tp17744203p17748987.html Sent from the R help mailing list archive at Nabble.com.