Skip to content

Instantly share code, notes, and snippets.

@mike-lawrence
Last active May 12, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-lawrence/6942b5882d67103eb90a8306c860b3cc to your computer and use it in GitHub Desktop.
Save mike-lawrence/6942b5882d67103eb90a8306c860b3cc to your computer and use it in GitHub Desktop.
Read a file incrementally in R, when that file is being occasionally written to by another process
fname = 'temp.txt'
#wait for it to exist
while(!file.exists(fname)){}
old = 0
new = old
while(T){
while(new==old){
new = file.size(fname)
}
f = file(
description = fname
, open = 'rb'
)
seek(con = f, origin = 'start', where = old)
temp = readLines(f)
#show a bit of info
print(c(length(temp),substr(temp[1],1,1),old,new))
close(f)
old = new
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment