Last active
May 12, 2017 17:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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