Watch a File or Directory for Changes
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.
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")
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"
GPL-3 © Gábor Csárdi
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.