jacobbien/litr-project

Corrupted lazy-load database when knitting `create-litr.Rmd`

patrickvossler18 opened this issue · 1 comments

When I get to the document and test section of knitting creat-litr.Rmd I get the following error message:

Error in eapply(ns_env(name), force, all.names = TRUE) : 
  lazy-load database '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/litr/R/litr.rdb' is corrupt
Calls: local ... <Anonymous> -> unregister -> unregister_namespace -> eapply
In addition: Warning message:
In eapply(ns_env(name), force, all.names = TRUE) :
  internal error -3 in R_decompress1
Execution halted
Quitting from lines 1065-1072 (create-litr.Rmd) 
Error: Failed to run 'test_litr' in a new R session.
Execution halted
Error: Failed to run 'render_' in a new R session.
Execution halted

It appears this is happening when we call xfun::Rscript_call(test_litr). This error typically goes away after restarting one's R session, but we can't do that when we're knitting our file. I've also successfully replicated this error on a different computer.

From the discussion here and here, my guess is that this is happening because of changes tolitr after it has been loaded.

The fix that works for me is to unload the package before calling devtools::install(location_of_new) in test_litr:

test_litr <- function(install_old, location_of_new) {
  devtools::unload(params$package_name)
  devtools::install(location_of_new)
  out <- devtools::test(location_of_new)
  install_old()
  return(out)
}