Skip to content
Prev 250763 / 398498 Next

monitor variable change

One way to implement this functionality is with a task manager callback:

watch <- function(varname) {
  old <- get(varname)

  changed <- function(...) {
    new <- get(varname)
    if (!identical(old, new)) {
      message(varname, " is now ", new)
      old <<- new
    }
    TRUE
  }
  invisible(addTaskCallback(changed))
}

a <- 1
watch("a")
a <- 2


Hadley
On Wed, Feb 16, 2011 at 9:38 AM, Alaios <alaios at yahoo.com> wrote: