0

I received the following error when knitting a document:

Quitting from lines 583-704 (education_crime_final.Rmd) 
Error in lapply(X = X, FUN = FUN, ...) : 
  seek failed on /Users/neatlabs/Desktop/EdSpending_Crime/education_crime_final_cache/docx/model building_7427809df73101b7d200e89c1a229cdc.rdb
Calls: <Anonymous> ... withVisible -> eval -> eval -> mean -> sapply -> lapply
Execution halted

I think this is a size issue but only because I came across a google result that talked about the issue with microsoft. I trouble shot the issue down to: if I continued asking for the same object `r mean(sapply(ed_crime.model.2.imp$analys, AIC)) - mean(sapply(ed_crime.model.1.imp$analys, AIC))`, down to `r mean(sapply(ed_crime.model.2.imp$analys, AIC))`, the knitr continued fine; however, when I started asking for new models `r mean(sapply(ed_crime.model.5.imp$analys, AIC)) - mean(sapply(ed_crime.model.4.imp$analys, AIC))`, down to `r mean(sapply(ed_crime.model.5.imp$analys, AIC))` I would get the above error.

Does anyone know how this can be fixed? I get that people want a reproducible example, but I'd have to give you a very large file and a lot of code in order to reproduce it. Hoping that someone here has come across this before.

James
  • 459
  • 2
  • 14
  • Can you use some [debugging methods](https://stackoverflow.com/questions/4442518/general-suggestions-for-debugging-in-r) or `tryCatch` as in [here](https://stackoverflow.com/questions/34908018/error-handling-with-lapply-output-the-index-of-failed-elements) – akrun Jul 07 '20 at 20:40
  • I am assuming that at least one of the list elements are either NULL or not generating AIC in the new models – akrun Jul 07 '20 at 20:43
  • Yeah, so if I try it in Rmarkdown vs running knitr, all of the functions with yield model output; that's why I also think it may be a size issue. I looked at the debugging methods; I'll see what I can do. – James Jul 07 '20 at 21:16
  • Sorry, without a reproducible example, it is a bit difficult for others to test your exact case – akrun Jul 07 '20 at 21:17
  • Hmmm...Does this help? Rather than pulling the mean, I just tried pulling one of the values from the MICE output with AIC(logLik(model$analys[[2]])) and I get the following: ```Error in logLik(ed_crime.model.7.imp$analys[[2]]) : seek failed on /Users/neatlabs/Desktop/EdSpending_Crime/education_crime_final_cache/docx/model building_7427809df73101b7d200e89c1a229cdc.rdb Calls: ... hook_eval -> withVisible -> eval -> eval -> AIC -> logLik Execution halted``` I don't think sapply is what is important here. – James Jul 07 '20 at 23:02
  • So I looked at my cache folder, and I think I've located the issue to be that a handful of models (or other objects involved with knitr) are consuming such a large amount of memory that models are no longer being saved to the cache folder. It looks like there is one object with memory of 3gb and a handful of others with 2gb. Probably has something to do with MICE and modeling all five imputed datasets. Would there be a fix for this...to somehow shrink the size? – James Jul 08 '20 at 00:55

1 Answers1

1

Anyone coming across this (incredibly annoying) issue; it is mostly likely a size issue. Check your cache...if you have large datasets and objects over gigabytes then you need to set lazy.cache to false: you can either do this by chunk with (cache.lazy=FALSE) or you can put knitr::opts_chunk$set(cache.lazy=FALSE) at the top of the Rmarkdown to enforce this globally. Here's a 2013 post...but it's relevant to the issue: https://github.com/yihui/knitr/issues/572

James
  • 459
  • 2
  • 14