Currently hydroPSO leaves dangling fileconnections and the parallel cluster (if used) open in case the function exits unorderly (errors, hitting escape in the console), which can lead to problems on subsequent runs. These commits use on.exit() to clean up connections.
The fix for the file connections looks a bit messy - but setting them to NULL after closing and checking for NULL before closing is required since if (isopen(fcon) close(fcon) throws an error if fcon has been closed previously (discussion). Patch only guards the files opened in the main loop if writedisk is TRUE, but that should be where the problem occurs in nearly all of the cases.
If you want to have this solved differently, let me know and I can revise.
Currently hydroPSO leaves dangling fileconnections and the parallel cluster (if used) open in case the function exits unorderly (errors, hitting escape in the console), which can lead to problems on subsequent runs. These commits use on.exit() to clean up connections.
The fix for the file connections looks a bit messy - but setting them to NULL after closing and checking for NULL before closing is required since
if (isopen(fcon) close(fcon)
throws an error if fcon has been closed previously (discussion). Patch only guards the files opened in the main loop if writedisk is TRUE, but that should be where the problem occurs in nearly all of the cases.If you want to have this solved differently, let me know and I can revise.