Gianni,

Please do not send a message to two lists at the same time.

You do not need to know beforehand how many lines the file has; just keep
reading until you reach the end. Also, you should avoid processing data
line by line; that is way too slow; I would use chunks of 10000 lines or
more. The below shows how you can find out how many lines there are (but
instead of finding out, you could put your code inside the loop).

file <- "C:/data.txt"
con  <- file(file, open = "r")
n <- 10000
i <- 0
while ( length( d <- readLines(con, n=n, warn=FALSE)) > 0 ) {
 i <- i + length(d)
}
close(con)
i


Robert


On Sun, Feb 26, 2012 at 6:03 AM, gianni lavaredo
<gianni.lavaredo@gmail.com>wrote:

> Dear Researchers,
>
> I have a large TXT (X,Y,MyValue) file in a directory and I wish to import
> row by row the txt in a loop to save only the data they are inside a buffer
> (using inside.owin of spatstat) and delete the rest. The first step before
> to create a loop row-by-row is to know how many rows there are in the txt
> file without load in R to save memory problem.
>
> some people know the specific function?
>
> thanks in advance for all suggestions
> Gianni
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

