Re: [R] readLines problem in iteration

From: jim holtman <jholtman_at_gmail.com>
Date: Sun, 22 Jun 2008 19:05:48 -0400

What is the value of 'line' on the first iteration? It appears to be undefined. You probably want something like this:

while (TRUE){

    line <- readLines(con, n=1)
    if (length(line) == 0) break
    .....your normal statements.....
}

On Sun, Jun 22, 2008 at 3:29 PM, Yasin Hajizadeh <yasin_reservoir_at_yahoo.com> wrote:
> Hi there
> My script at each iteration produces a .dat file which I save in a directory with write.table. Then I need to read each line of this file and create a directory for each line and put elements of that row in that directory. I do it with the following script which I have inserted somewhere between my outer iteration loop, it works fine for the first iteration, but the problem is that it does nothing at next iterations. How can I solve this problem, is there anything wrong with my code?
> Thanks in advance for your help.
>
>
> write.table(X, file = "model.dat", append = FALSE, sep = " ", eol = "\n", na = "NA", dec = ".", row.names = FALSE, col.names = FALSE, qmethod = c("escape", "double"))
>
> mother<-getwd()
>
>
> count <- 0;
>
> con<- file("model.dat", open="r")
>
>
> while (length(line) > 0) {
>
> line<-readLines(con,n=1)
> count <- count +1
> cat("read row no", count, ",\n", sep="");
> print(line)
>
> foldername <- paste("Iteration",c, "ant", count)
> dir.create (foldername)
>
> setwd(foldername)
> write.table(line, file = "params.in", append = FALSE, sep = " ", eol = "\n", na = "NA", dec = ".", row.names = FALSE, col.names = FALSE, qmethod = c("escape", "double"))
>
> #system(run_misf_calc.py)
>
> setwd(mother)
>
>
> }
>
>
> close(con)
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_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
> 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?

______________________________________________
R-help_at_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
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 23 Jun 2008 - 00:13:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 01:30:52 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.

list of date sections of archive