Created
May 13, 2012 20:40
-
-
Save lgatto/2690073 to your computer and use it in GitHub Desktop.
Monitor a variable in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Credit Hadley Wickham | |
## http://www.mail-archive.com/r-help@r-project.org/msg125980.html | |
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)) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> a <- 1 | |
> watch("a") | |
> a <- 2 | |
a is now 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment