diff --git a/R/monitor.R b/R/monitor.R index 1052fa6..025eca8 100644 --- a/R/monitor.R +++ b/R/monitor.R @@ -11,9 +11,9 @@ #' @param file String, file path. Path to the R script to rerun when changes #' are detected. #' @param ext Character vector. File extensions to watch. -#' Defaults to `c(".R", ".r")` files. +#' "*" (the default) watches all files in `dir`. #' @param monitor_hidden Logical. Should hidden files be monitored for changes? -#' Default is `FALSE`. +#' Default is `TRUE`. #' Hidden files are those whose names start with a dot eg. `.Renviron`, `.env`, #' etc. #' This option is especially helpful when `ext = "*"`. @@ -43,8 +43,6 @@ #' rmon::monitor( #' dir = ".", #' file = "app.R", -#' ext = "*", -#' monitor_hidden = TRUE, #' exclude_files = "dev.R", #' exclude_dirs = "test" #' ) @@ -61,18 +59,20 @@ monitor <- function( dir = getwd(), file, - ext = c(".R", ".r"), - monitor_hidden = FALSE, + ext = "*", + monitor_hidden = TRUE, exclude_files = NULL, exclude_patterns = NULL, exclude_dirs = NULL, delay = 1) { - file <- normalizePath(path = file.path(dir[[1]], file)) + file <- normalizePath(path = file.path(dir[[1]], file[[1]])) if (!file.exists(file)) { msg <- sprintf("File '%s' not found!", file) stop(msg, call. = FALSE) } + patterns <- paste0(ext, "$", collapse = "|") + now <- function() { format(Sys.time(), "%c") } @@ -88,12 +88,6 @@ monitor <- function( ) get_file_info <- function() { - patterns <- paste0( - "\\.", - gsub(pattern = "\\.", replacement = "", x = ext), - collapse = "|" - ) - files <- list.files( path = dir, pattern = patterns, diff --git a/README.md b/README.md index 287b8c2..2f1bdb1 100644 --- a/README.md +++ b/README.md @@ -38,16 +38,19 @@ rmon::monitor( ```r rmon::monitor( - dir = c(".", "path-to-another-dir"), + dir = c("path-to-first-dir", "path-to-another-dir"), file = "app.R" ) ``` +if multiple directories are specified, `file` is assumed to be in the first +directory. + # specify extension watch list -by default, `{rmon}` monitors only `.R` files in `dir` for changes. +by default, `{rmon}` monitors all files in `dir` for changes. -to watch `.R`, `.html`, `.css` and `.js` files: +to watch only `.R`, `.html`, `.css` and `.js` files, set the `ext` parameter: ```r rmon::monitor( @@ -57,10 +60,6 @@ rmon::monitor( ) ``` -- `ext`: character vector. extensions to watch. - -specifying `ext = "*"` watches all files in `dir` for changes. - # ignoring files to ignore the file `dev.R`, do: @@ -73,31 +72,36 @@ rmon::monitor( ) ``` -- `exclude_files`: character vector - -to ignore the directory `test/` as well: +to ignore the directory `test/`: ```r rmon::monitor( dir = ".", file = "app.R", - exclude_files = "dev.R" exclude_dirs = "test" ) ``` -to ignore all files whose names match the pattern `test` as well: +to ignore all files whose names match the pattern `test`: ```r rmon::monitor( dir = ".", file = "app.R", - exclude_files = "dev.R" - exclude_dirs = c("test"), exclude_patterns = "test" ) ``` +to ignore changes to hidden files, set `monitor_hidden = FALSE`: + +```r +rmon::monitor( + dir = ".", + file = "app.R", + monitor_hidden = FALSE +) +``` + # delaying restarting in some situations, you may want to delay restarting until multiple files have changed. diff --git a/man/monitor.Rd b/man/monitor.Rd index 2e4161f..6df21cc 100644 --- a/man/monitor.Rd +++ b/man/monitor.Rd @@ -7,8 +7,8 @@ monitor( dir = getwd(), file, - ext = c(".R", ".r"), - monitor_hidden = FALSE, + ext = "*", + monitor_hidden = TRUE, exclude_files = NULL, exclude_patterns = NULL, exclude_dirs = NULL, @@ -23,10 +23,10 @@ Defaults to the current working directory.} are detected.} \item{ext}{Character vector. File extensions to watch. -Defaults to \code{c(".R", ".r")} files.} +"*" (the default) watches all files in \code{dir}.} \item{monitor_hidden}{Logical. Should hidden files be monitored for changes? -Default is \code{FALSE}. +Default is \code{TRUE}. Hidden files are those whose names start with a dot eg. \code{.Renviron}, \code{.env}, etc. This option is especially helpful when \code{ext = "*"}.} @@ -67,8 +67,6 @@ The function runs indefinitely until interrupted. rmon::monitor( dir = ".", file = "app.R", - ext = "*", - monitor_hidden = TRUE, exclude_files = "dev.R", exclude_dirs = "test" )