Open shainen opened 5 years ago
I don't think this is possible. The cache code calls eval
on the code in the curly braces. eval
doesn't have error trapping capabilities. That is, it doesn't return a string with any errors it encountered. Instead if there is an error, the error is thrown by eval
, which is what you are seeing.
@connectedblue would you have any thoughts on how to trap errors in the cache function?
Hi all
It's been a while since I wrote R code - I've spent the last 9 months in back in python (where funnily enough I had to also write some caching utilities).
However, I'll put this on my to do list to have a look at. I vaguely remember some error trapping techniques in a project somewhere.
On Wed, 27 Mar 2019, 15:03 Kenton White, notifications@github.com wrote:
I don't think this is possible. The cache code calls eval on the code in the curly braces. eval doesn't have error trapping capabilities. That is, it doesn't return a string with any errors it encountered. Instead if there is an error, the error is thrown by eval, which is what you are seeing.
@connectedblue https://github.com/connectedblue would you have any thoughts on how to trap errors in the cache function?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/KentonWhite/ProjectTemplate/issues/292#issuecomment-477197245, or mute the thread https://github.com/notifications/unsubscribe-auth/APwt6ZaSurgaQaWsqfAaMB6oIZk2Przvks5va4g-gaJpZM4blqtU .
In the "depends" list in the "cache" function, when I put in a variable that does not exist (generally by accident), the error I get is "Error in if (nrow(depends.hash) >= 1) { : argument is of length zero"
Unless you know the mistake you've made, its hard to tell from this error message that you've made a typo in the your "depends" variables. Would probably save some head scratching if the error was something more like "Error, variable "x" in dependencies is not found in the current environment"
PS: Here is some code that will generate the error for me: cache("new_var", { x <- 56 }, depends = c("old_var"))