Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dump.frames call in-code comments to mention new argument include.GlobalEnv (since R 3.4.2) #78

Open
aryoda opened this issue Feb 13, 2023 · 0 comments

Comments

@aryoda
Copy link
Owner

aryoda commented Feb 13, 2023

tryCatchLog uses a work-around to include the global env in dump files since R did not support when the code was created.

Since R 3.4.2 (Sept, 28, 2017) this missing feature was implemented:

https://www.math.uzh.ch/sepp/r-3.4.2-jenkins/NEWS.html

dump.frames() gets a new option include.GlobalEnv which allows to also dump the global environment, thanks to Andreas Kersting's proposal in PR#17116.

Nevertheless the work-around will stay to support older R versions, see:

tryCatchLog/DESCRIPTION

Lines 15 to 16 in 7943c0e

Depends:
R (>= 3.1.0)

Please add this explanation to the code comments to explain why the work-around is still in-place:

tryCatchLog/R/tryCatchLog.R

Lines 274 to 295 in 7943c0e

# Save dump to allow post mortem debugging?
if (write.error.dump.file == TRUE & severity == "ERROR") {
# See"?dump.frames" on how to load and debug the dump in a later interactive R session!
# See https://stackoverflow.com/questions/40421552/r-how-make-dump-frames-include-all-variables-for-later-post-mortem-debugging/40431711#40431711
# why you should avoid dump.frames(to.file = TRUE)...
# https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17116
# An enhanced version of "dump.frames" was released in spring 2017 but does still not fulfill the requirements of tryCatchLog:
# dump.frames(dumpto = dump.file.name, to.file = TRUE, include.GlobalEnv = TRUE) # test it yourself!
# See ?strptime for the available formatting codes...
#
# Creates a (hopefully) unique dump file name even in case of multiple parallel processes
# or multiple sequential errors in the same R process.
# Fixes issue #39 by appending fractional seconds (milliseconds) and the process id (PID)
# https://github.com/aryoda/tryCatchLog/issues/39
# Example dump file name: dump_2019-03-13_at_15-39-33.086_PID_15270.rda
dump.file.name <- paste0(format(timestamp, format = "dump_%Y-%m-%d_at_%H-%M-%OS3"), "_PID_", Sys.getpid(), ".rda") # %OS3 (= seconds incl. milliseconds)
dir.create(path = write.error.dump.folder, recursive = T, showWarnings = F)
utils::dump.frames()
save.image(file = file.path(write.error.dump.folder, dump.file.name)) # an existing file would be overwritten silently :-()
log.entry$dump.file.name <- dump.file.name
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant