我有一个监视某些文件更改的程序。文件更新后,即会对其进行处理。到目前为止,我已经提出了在R中处理“实时分析”的一般方法。我希望你们还有其他方法。也许我们可以讨论它们的优缺点。
monitor <- TRUE
start.state <- file.info$mtime # modification time of the file when initiating
while(monitor) {
change.state <- file.info$mtime
if(start.state < change.state) {
#process
} else {
print("Nothing new.")
}
Sys.sleep(sleep.time)
}
最佳答案
与使用系统API的建议类似,也可以使用qtbase来完成,这将是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")
关于r - 实时监控文件更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4780632/