Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created January 7, 2025 22:52
Show Gist options
  • Save JosiahParry/e76a948824ae54730fcbe8f57da1d251 to your computer and use it in GitHub Desktop.
Save JosiahParry/e76a948824ae54730fcbe8f57da1d251 to your computer and use it in GitHub Desktop.
callback log function?
log <- tempfile(fileext = ".log")
con <- file(log, open = "a")
addTaskCallback(
function(expr, value, ok, visible) {
if (rlang::is_condition(value)) {
write("Found a condition!!!!", con, append = TRUE)
}
if (visible) {
msg <- sprintf("[%sZ] > %s", format(Sys.time()), format(expr))
write(msg, con, append = TRUE)
write(
sprintf("[%sZ] #> %s", format(Sys.time()), capture.output(print(value))),
con, append = TRUE
)
} else {
write(
sprintf("[%sZ] > %s", format(Sys.time()), format(expr)),
con, append = TRUE
)
}
TRUE
},
name = "add log"
)
x <- 1
x
x
warning("My message")
head(iris)
cat(readLines(log), sep = "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment