Home Comments Thread
New Thread

2 Comments

giscus-bot giscus-bot 2022-12-17 06:25:56
Guest *Santiago* @ 2021-04-18 20:06:07 originally posted:

I have been looking for something like this!!

Although, I cannot set it to work properly... I can replay de example (print_time ), but I am failing to run muy own functions with this approach...

I would really appreciate some help! Thank you!

print_time = function(interval = 5) {
i <<- i + 1
if(i <= 5){
print("hello") ##works as expected
print(i) ## works as expected

nrow(GGAL_t) ##it is as if it is not written :(
later::later(print_time, interval)
}
}

print_time()

yihui yihui 2022-12-17 06:25:58

I'm not sure what you want to achieve, but it seems you forgot to print() the value you want to see. You may check out this post for more info: https://yihui.org/en/2017/06/top-level-r-expressions/

Originally posted on 2021-04-19 02:39:16

giscus-bot giscus-bot 2022-12-17 06:25:57
Guest *sylvertwyst* @ 2021-12-17 08:27:00 originally posted:

This looks like exactly the kind of thing i need! I tested it in my code and it works when run in the R interpreter in Rstudio, but when i run it from terminal with Rscript script.R, it stops after 1 single execution. does the Rscript command not wait for background R threads to finish?

yihui yihui 2022-12-17 06:25:59

It's not that Rscript does not wait. It's that later() does not wait, which is expected, since it does not mean to block an R session. When R quits, it just quits.

The title of this blog post says "the current R session", which actually means an interactive R session. Rscript starts a non-interactive R session. If you want to execute code periodically in a non-interactive R session, why not use an infinite loop? e.g., while (TRUE) { print(i) }.

Originally posted on 2021-12-17 14:43:41

Sign in to join the discussion

Sign in with GitHub