Created
January 7, 2025 22:52
-
-
Save JosiahParry/e76a948824ae54730fcbe8f57da1d251 to your computer and use it in GitHub Desktop.
callback log function?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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