Skip to contents

This function may be used to rapidly develop visualizations by replacing a workflow of reloading and executing code manually.

Usage

hgd_watch(
  watch = list.files(pattern = "\\.R$", ignore.case = T),
  on_change = function(changed_files) {
     print(changed_files)
 },
  interval = 1,
  on_start = hgd_browse,
  on_exit = NULL,
  on_error = print,
  reset_par = TRUE,
  ...
)

Arguments

watch

Paths that are watched for changes (see utils::fileSnapshot())

on_change

Will be called when a file changes.

interval

Time interval in which changes are detected (in seconds).

on_start

Will be called after the httpgd server is started (may be set to NULL).

on_exit

Will be called before the server is closed (may be set to NULL).

on_error

Will be called when on_change throws an error (may be set to NULL).

reset_par

If set to TRUE, global graphics parameters will be saved on device start and reset every time unigd::ugd_clear() is called (see graphics::par()).

...

Additional parameters passed to hgd(webserver=FALSE, ...)

Examples

if (FALSE) {

# --- my_code.R ---

plot(rnorm(100), col = "red")

# --- Other file / interactive ---

hgd_watch(
  watch = "my_code.R", # When my_code.R changes...
  on_change = function(...) {
    source("my_code.R") # ...call updated plot function.
  }
)
}