Displaying 1 result from an estimated 1 matches for "txt_line".
2012 Jun 06
3
extracting values from txt file that follow user-supplied quote
...altered if one desires to test code on the
attached txt file, which will run much quicker
system.time(num_lines<-countLines("D:/MCR_BeoPEST - Copy/MCR.out"))
#elapsed time on full 1Gb file took about 55 seconds on a 3.6Gh Xeon
num_lines
#14405247
system.time(
for(i in 1:num_lines){
txt_line<-readLines(txt_con,n=1)
if (length(grep(" PERCENT DISCREPANCY =",txt_line))) {
pd<-c(pd,as.numeric(substr(txt_line,70,78)))
}
}
)
#Time took about 5 minutes
The inefficiencies in this approach arise due to reading the file twice
(first to get num_lines, then to step thro...