-----Original Message-----
From: Robert Gentleman [mailto:rgentlem at jimmy.harvard.edu]
Sent: Tuesday, October 02, 2001 9:50 AM
To: Liaw, Andy
Subject: Re: [R] file connection, while, readLines and browser
On Tue, Oct 02, 2001 at 09:28:49AM -0400, Liaw, Andy wrote:
Dear R-help,
I have one more question about the functions mentioned in
Again, the system info is:
platform i386-pc-mingw32
arch x86
os Win32 (OK, it's NT4sp6)
system x86, Win32
status
major 1
minor 3.1
year 2001
month 08
day 31
language R
I defined a function like the following:
myfun <- function(file, maxline) {
f.con <- file(file, open="rt")
on.exit(close(f.con))
while(length(readln <- readLines(f.con, 1)) > 0 ) {
## Do something with readln...
}
## Do something more...
}
This didn't work for me. It gave me an error at the while
"NA where logical needed". I inserted a browser() right
loop and have it step through the function. It seems to be
first line of the file and never move down. This behaviour
from the call without the browser(). Anyone has ideas why
It seems to work for me. Are you sure that's what you did? It is best
not to edit anything, get a simple example that shows the error and
post that. It makes for a lot less work for those of us that are
willing to look at it and it makes sure that we find the problem that
you are having.
What had worked for me is something like the following:
repeat {
readln <- readLines(f.con, 1)
if(length(readln) == 0) break
## do something...
}
Any suggestions are greatly appreciated.
Regards,
Andy
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-.-.-.-.-.-
r-help mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._._._._._._
--
+-------------------------------------------------------------
--------------+
| Robert Gentleman phone : (617) 632-5250
|
| Associate Professor fax: (617) 632-2444
|
| Department of Biostatistics office: M1B28
| Harvard School of Public Health email:
rgentlem at jimmy.dfci.harvard.edu |
+-------------------------------------------------------------
--------------+