| monitor | R Documentation |
Monitors specified directories for file changes and reruns a designated R script when changes are detected. It's designed to automate the process of reloading your R applications during development, similar to nodemon for Node.js.
monitor(
dir,
file,
ext = "*",
monitor_hidden = FALSE,
exclude_files = NULL,
exclude_patterns = NULL,
exclude_dirs = NULL,
delay = 1
)
dir |
Character vector. Directory or directories to monitor for changes. |
file |
String, file path. Path to the R script to rerun when changes are detected. |
ext |
Character vector. File extensions to watch.
"*" (the default) watches all files in |
|
Logical. Should hidden files be monitored for changes?
Default is | |
exclude_files |
Character vector. Specific files to ignore. Changes
to these files will not trigger a script rerun. Default is |
exclude_patterns |
Character vector. File name patterns to ignore. Any
files in |
exclude_dirs |
Character vector. Directories to exclude from
monitoring. Default is |
delay |
Numeric. Number of seconds to wait before checking
for file changes. Defaults to |
The monitoring process can be customized by excluding specific files, file patterns, or entire directories. This allows you to ignore changes to files that shouldn't trigger a reload (eg. temporary files, log files, etc.).
If multiple directories are supplied, file is assumed to be in the first
directory.
The function runs indefinitely until interrupted.
NULL
if (interactive()) {
# monitor current directory, rerun 'app.R' on changes, ignore 'dev.R' and
# any files in 'test/' directory:
rmon::monitor(
dir = ".",
file = "app.R",
exclude_files = "dev.R",
exclude_dirs = "test"
)
# monitor multiple directories, watch only `.R` & `.Rmd` files:
rmon::monitor(
dir = c("src", "scripts"),
file = "main.R",
ext = c(".R", ".Rmd")
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.