我有一个文件Timer.R
,我想在与交互式R会话分开的进程中执行。
# In Timer.R
library(tcltk)
z <- function () {
cat("Hello you!\n")
.id <<- tcl("after", 1000, z)
}
.id <<- tcl("after", 1000, z)
tcl("after", "info", .id) # To get info about this scheduled task
tcl("after", "cancel", .id) # To cancel the currently scheduled task
麻烦的是,Rscript
不是持久性的 - 当它到达文件末尾时终止:
# In interactive session
system("C:/Program Files/R/R-3.0.2/bin/Rscript.exe Test.R", invisible = FALSE)
<Tcl> {R_call 00000000217CD078} timer
<Tcl>
> # Rscript has terminated by this point - timer is never run
有没有办法让Timer.R
在后台持续运行?