CancerRegistryOfNorway / nordcansurvival

Other
0 stars 0 forks source link

Improve robustness of call_stata_script #9

Closed WetRobot closed 3 years ago

WetRobot commented 3 years ago

A NORDCAN participant just had the error

List of 2
 $ message: chr "cannot change working directory"
 $ call   : language setwd(old_wd)
 - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

while computing survival. This comes from

https://github.com/CancerRegistryOfNorway/nordcansurvival/blob/79957e431e6ab309d6f615b43a0118920e0e9be1/R/utils.R#L30

The cause is likely the fact that the user was using a network drive, and the network drive became unavailable to R for a fraction of a second, i.e. bad luck.

call_stata_script should be made more robust. Actually changing the R working directory is more of a hack than a solution in the first place, so preferably the need for doing it would be removed. An additional hack could be trying e.g. 10 times over 10 seconds to change the working directory --- this would protect against temporary network drive unavailability to some extent at least.

To be clear, the working directory is changed two times within that function, and both instances should be either removed or made into a more robust hack.

WetRobot commented 3 years ago

Robustness was improved even if the solution is a bit of a hack, so I'm closing this.