I am having an issue: I am running a loop to process multiple files. My matrices are enormous and therefore I often run out of memory if I am not careful.
Is there a way to break out of a loop if any warnings are created? It just keeps running the loop and reports that it failed much later... annoying. Any ideas oh wise stackoverflow-ers?!
Set the global
warn
option:Note that a "warning" is not an "error". Loops don't terminate for warnings (unless
options(warn=2)
).R allows you to define a condition handler
which results in
Execution continues after tryCatch; you could decide to end by converting your warning to an error
or handle the condition gracefully (continuing evaluation after the warning call)
which prints
You can turn warnings into errors with:
Unlike warnings, errors will interrupt the loop. Nicely, R will also report to you that these particular errors were converted from warnings.