r - 实时监控文件更改

标签 r monitoring real-time

我有一个监视某些文件更改的程序。文件更新后,即会对其进行处理。到目前为止,我已经提出了在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/

相关文章:

r - 仅过滤完整的年份集

python - 根据系统资源使用情况监视和终止 Python 脚本

Android MediaCodec 实时 h264 编码/解码延迟

r - 计算 AME、MEM、MER 的最简单方法?

r - 在 OS 10.8.2 上安装 R 库 XLConnect

readxl::read_xls 返回 "libxls error: Unable to open file"

java - 两个线程之间如何通信

Spring Actuator - 来自 docker 容器的指标聚合

python - 如何使用 matplotlib 实时绘制条形图

Android实时游戏——实现时间单位