Description Usage Arguments Value Author(s) See Also Examples
Tcl allows fo scheduling execution of code on the next event loop or after a
given time (after
Tcl command). tclTaskXxx()
functions use it to
schedule execution of R code with much control from within R (central
management of scheduled tasks, possibility to define redoable tasks, use of S3
objects to keep track of tasks information. The tclAfterXxx()
functions
are low-level access to the Tcl after
command.
1 2 3 4 5 6 7 8 9 10 11 | ## Convenient tclTask objects management
tclTaskSchedule(wait, expr, id = "task#", redo = FALSE)
tclTaskRun(id)
tclTaskGet(id = NULL, all = FALSE)
tclTaskChange(id, expr, wait, redo)
tclTaskDelete(id)
## Low-level Tcl functions
tclAfter(wait, fun)
tclAfterCancel(task)
tclAfterInfo(task = NULL)
|
wait |
time in ms to delay the task (take care: approximative value, depends on when event loops are triggered). Using a value lower or equal to zero, the task is scheduled on the next event loop. |
fun |
name of the R function to run (you may not supply arguments to this function, otherwise it is not scheduled properly; take care of scoping, since a copy of the function will be run from within Tcl). |
expr |
an expression to run after 'wait'. |
id |
the R identifier of the task to schedule, if this id contains
|
all |
if |
redo |
should the task be rescheduled n times, indefinitely
( |
task |
a Tcl task timer, or its name in Tcl (in the form of 'after#xxx'). |
The tclAfterXxx()
functions return a 'tclObj' with the result of the
corresponding Tcl function. tclAfter()
returns the created Tcl timer in
this object. If 'task' does not ecxists, tclAfterInfo()
returns
NULL
.
tclTaskGet()
returns a 'tclTask' object, a list of such objects, or
NULL
if not found.
The four remaining tclTaskXxx()
functions return invisibly TRUE
if the process is done successfully, FALSE
otherwise.
tclTaskRun()
forces running a task now, even if it is scheduled later.
Philippe Grosjean
tclFun
, addTaskCallback
,
Sys.sleep
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ## Not run:
## 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)
## End(Not run)
|
Loading required package: tcltk
Warning message:
no DISPLAY variable so Tk is not available
==== Hello from Tcl! ====
==== Hello again from Tcl! ====
==== Hello again from Tcl! ====
==== First message ====
==== Hello again from Tcl! ====
==== Second message ====
==== Hello again from Tcl! ====
==== Second message ====
[1] "test2" "test3"
tclTask 'test2' scheduled after 1000 ms (elapsed)
Rescheduled 6 times
runs:
test2()
<Tcl> after#9 after#8
==== Hello again from Tcl! ====
==== Second message ====
==== Hello again from Tcl! ====
==== Hello again from Tcl! ====
==== Hello again from Tcl! ====
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.