monitoring for changes in file(s) in real time

Similar to the suggestion to use a system API, this can be also done using qtbase which will be a cross-platform means from within R:

dir_to_watch <- "/tmp"

library(qtbase)
fsw <- Qt$QFileSystemWatcher()
fsw$addPath(dir_to_watch)

id <- qconnect(fsw, "directoryChanged", function(path) {
  message(sprintf("directory %s has changed", path))
})

cat("abc", file="/tmp/deleteme.txt")

If your system provides an API for monitoring filesystem changes, then you should use that. I believe Macs come with this. Not sure about other platforms though.

Edit: A quick goog gave me:

Linux - http://wiki.linuxquestions.org/wiki/FAM

Win32 - http://msdn.microsoft.com/en-us/library/aa364417(VS.85).aspx

Obviously, these APIs will eliminate any polling that you require. On the other hand, they may not always be available.

Java has this: http://jnotify.sourceforge.net/ and http://java.sun.com/developer/technicalArticles/javase/nio/#6


I have a hack in mind: you can setup a CRON job/Scheduled task to run R script every n seconds (or whatever). R script checks the file hash, and if hashes don't match, runs the analysis. You can use digest::digest function, just check out the manual.