[R] Reading a file every t seg.

Don MacQueen macq at llnl.gov
Mon Jul 28 22:34:24 CEST 2003


Is data being appended to the file, or is the file being overwritten 
with the new data?

For the former case, I use the $size element returned by file.info() 
to watch for changes in size, and when the size has changed, use 
pipe() and the unix tail command to get the latest data. My data, 
however, is arriving once per minute, so I can use a 5 second pause 
to make sure the data has all arrived.

For the latter case, you might be able to use one of the 'time' 
elements from file.info(). Or perhaps check how many lines the file 
has before trying to read it. If it has zero lines, don't try to 
read, keep waiting instead.

-Don

At 3:08 PM -0300 7/28/03, Marlon Martins dos Reis wrote:
>Dear all,
>I'm writing a small program to read a file that receives data every time
>(e.g. every 1second ). During the execution of my program I get the
>message:
>" Error in read.table("file.txt", header = T, sep = ";") :
>         no lines available in input "
>I suppose that it happens when I try to read the "file.txt" while it is
>being written. To overcome this problem I have tried the following:
>
>while(!is.numeric(try(read.table('file.txt',header =T, sep =
>";")$tempo))){Sys.sleep(2)}
>
>It seems to work, although after three times the message
>" Error in read.table("file.txt", header = T, sep = ";") :
>         no lines available in input "
>is shown, the program stops.
>Is there another way of checking if I can try to read a file?
>Thanks in advance,
>Reagrds,
>Marlon !!!
>marlon at lscp.pqi.ep.usp.br
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list