fswatch: Watch a File or Directory for Changes

Description Usage Arguments Format Value Additional methods Examples

Description

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.

Usage

1
2
3
4
5
fswatch(path, callback, check_interval = 500)

## id <- fswatch(path, callback, check_interval = 500)
## fswatch$cancel(id)
## fswatch$list()

Arguments

path

Path to watch. It can be a directory or a file. Directories are watched recursively.

callback

Callback function to call when path is updated, i.e. the modification time of the file, or a file in the directory changed. The function will be called with one argument: a character vector of the changed files and directories.

check_interval

How long to wait between checks for changes, in milliseconds. Defaults to half a second.

Format

An object of class fswatch_package of length 1.

Value

The ID of the watcher. This can be used to cancel it later.

Additional methods

fswatch$list() lists all watchers.

fswatch$cancel(id cancels a watcher.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
id <- fswatch(tempdir(), callback = function(f) print(f))
tmp <- tempfile()
tmp
cat("hello", file = tmp)
Sys.sleep(1)
file.remove(tmp)
Sys.sleep(1)

fswatch$list()
fswatch$cancel(id)
fswatch$list()

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