[R] readLines problem in iteration

From: Yasin Hajizadeh <yasin_reservoir_at_yahoo.com>
Date: Sun, 22 Jun 2008 12:29:00 -0700 (PDT)


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. Received on Sun 22 Jun 2008 - 19:31:04 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 - 00:31:02 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