Hi all,
I am wondering if there's any way to see/create real-time logs when running long scripts.
Many thx!
Hi all,
I am wondering if there's any way to see/create real-time logs when running long scripts.
Many thx!
There's probably a more elegant way, but this might work for you. In this case, I'm saving a new log file after each step, to avoid causing problems if you want to open up the log file while the script runs.
There might be a way to use purrr::walk or safely to have it write a single log file, but fail gracefully if you happen to have opened the log file. In that case you'd miss updates until you close it. (Unless the failed open triggered a new file name... but then maybe it just gets too messy.)
library(tidyverse)
log <- tibble(timestamp = character(), note = character())
for(t in 1:10) {
# Do one step of your long script here
Sys.sleep(1)
# Add a row to the log
log <- log %>%
add_row(timestamp = Sys.time() %>% as.character(),
note = paste("Hello step", t))
# Save a new log file
write_csv(log, path = paste0("log_step",
stringr::str_pad(t,3,pad = 0),
".csv"))
}
I am using the futile.logger package to create a log file when running long scripts. With this log you can create log files or show the output in you R console. Both shows you the log entries in real time.
Some logging packages:
Another package that might be interesting
https://cran.r-project.org/web/packages/loggit/index.html
Whoops! Totally thought I'd included that one.
Thank you very much! Very helpful to my problem.
Thanks a lot! futile.logger is awesome.
Thank you Mara! These packages are amazing. Thanks for sharing!
Thank you very much! Another amazing tool!
There is also the ˋloggr` but still only on github
The one I've actually used, of course, is also one I forgot… (>ლ)