How to constantly execute rscript?

I have a file Timer.Rthat I want to execute in a separate process from my interactive session 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

The problem is that Rscriptit is not persistent - it terminates when it reaches the end of the file:

# 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

Is there a way to keep Timer.Rconstant work in the background?

+3
source share

All Articles