README.md

fswatch

Watch a File or Directory for Changes

Linux Build Status Windows Build status CRAN RStudio mirror downloads

Get notification is a file or any file in a directory changes. It uses the fswatch tool (see https://github.com/emcrisostomo/fswatch) and works on major platforms.

Installation

Make sure you install the standalone fswatch program first, from https://github.com/emcrisostomo/fswatch

Then install the R package as:

source("https://install-github.me/gaborcsardi/fswatch")

Usage

library(fswatch)

Create a directory and start watching it. The callback will simply print the file(s) that has changed.

tmp <- tempfile()
dir.create(tmp)
id <- fswatch(tmp, callback = function(f) print(f))

Now modify the directory to see a notification.

cat("hello", file = file.path(tmp, "foobar"))
#> [1] "/private/var/folders/ws/7rmdm_cn2pd8l1c3lqyycv0c0000gn/T/Rtmpgj5lSY/file12c557f73ef61/foobar"

Removing the file will also trigger a notification.

file.remove(file.path(tmp, "foobar"))
#> [1] "/private/var/folders/ws/7rmdm_cn2pd8l1c3lqyycv0c0000gn/T/Rtmpgj5lSY/file12c557f73ef61/foobar"

License

GPL-3 © Gábor Csárdi



gaborcsardi/fswatch documentation built on May 16, 2019, 4:09 p.m.