if (FALSE) {
## These cannot be run by examples() but should be OK when pasted
## into an interactive R session with the tcltk package loaded
## Run just once, after 1 sec
test <- function () cat("==== Hello from Tcl! ====\n")
tclTaskSchedule(1000, test())
Sys.sleep(2)
## Run ten times a task with a specified id
test2 <- function () cat("==== Hello again from Tcl! ====\n")
tclTaskSchedule(1000, test2(), id = "test2", redo = 10)
Sys.sleep(1)
## Run a function with arguments (will be evaluated in global environment)
test3 <- function (txt) cat(txt, "\n")
msg <- "==== First message ===="
tclTaskSchedule(1000, test3(msg), id = "test3", redo = TRUE)
Sys.sleep(2)
msg <- "==== Second message ===="
Sys.sleep(2)
## Get info on pending tasks
tclTaskGet() # List all (non hidden) tasks
tclTaskGet("test2")
## List all active Tcl timers
tclAfterInfo()
## Change a task (run 'test3' only once more, after 60 sec)
tclTaskChange("test3", wait = 60000, redo = 1)
Sys.sleep(1)
## ... but don't wait so long and force running 'test3' right now
tclTaskRun("test3")
Sys.sleep(3)
## finally, delete all pending tasks
tclTaskDelete(NULL)
}
Run the code above in your browser using DataLab