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

Post-mortem debugging: Clarify and document what happens to loaded packages when the dump is written and loaded again #12

Closed
aryoda opened this issue Nov 27, 2016 · 2 comments

Comments

@aryoda
Copy link
Owner

@aryoda aryoda commented Nov 27, 2016

What happens to the search path search(), are the loaded environments contained in the dump file or are the packages only referenced?

Does load load the packages again that were loaded when the dump was written?

...

@aryoda
Copy link
Owner Author

@aryoda aryoda commented Jan 1, 2017

Result:

save.image does NEITHER store the objects of the loaded packages ("namespaces") NOR the search path!

This means

  1. you cannot step through your source code in a reproducible way after loading the image
    if your source code calls functions of non-default packages
  2. the program state is not exactly reproducible if objects are stored within a package namespace

TODO

Document this in the function header of tryCatchLog and other (planned) documentations.

Proove:

# Test code to evaluate the "save.image" behaviour for loaded packages and the search path

initial.search <- search()
initial.loadedNamespaces <- loadedNamespaces()

library(data.table)
library(ggplot2)

current.search <- search()
current.loadedNamespaces <- loadedNamespaces()

save.image("test.Rdata")



stop("Restart the R session now")
# Now restart the R session to have a clean environment and check whether the loaded image
# contains the search path and loaded packages ("namespaces"):



load("test.Rdata")


search()
# [1] ".GlobalEnv" "tools:rstudio" "package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base"

initial.search
# [1] ".GlobalEnv" "tools:rstudio" "package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base"


setdiff(initial.search, search() )
# character(0)

loadedNamespaces()
# [1] "rsconnect" "graphics"  "tools"     "utils"     "grDevices" "stats"     "datasets"  "methods"   "base"     

initial.loadedNamespaces
# [1] "rsconnect" "graphics"  "tools"     "utils"     "grDevices" "stats"     "datasets"  "methods"   "base"     

# RESULT:
# "save.image" does NEITHER store the objects of the loaded packages ("namespaces") NOR the search path!
# This means you cannot step through your source code in a reproducible way after loading the image
# if your source code calls functions of non-default packages!

setdiff(initial.loadedNamespaces, loadedNamespaces())
# character(0)

current.search
# [1] ".GlobalEnv" "package:ggplot2" "package:data.table" "tools:rstudio" "package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base"

current.loadedNamespaces
# [1] "colorspace" "scales" "plyr" "rsconnect" "graphics" "tools" "gtable" "utils" "grDevices" "Rcpp" "stats" "ggplot2" "datasets" "grid" "data.table" "methods" "chron" "munsell" "base"


@aryoda
Copy link
Owner Author

@aryoda aryoda commented Jan 1, 2017

This behaviour is documented now in the help for the tryCatchLog function and in the training slides for error handling (see https://github.com/aryoda/R_trainings).

@aryoda aryoda closed this Jan 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.