[R] handling breaks in a for loop

Ebert,Timothy Aaron
2022-02-06T19:03:19Z

Is the bug in the data or in the code?
Can you identify the cause? Can you get a subset of the data to find the bug
using fewer resources?
If you can identify the root cause, then you can set an error trap.
If the error is a memory problem, they you either need to save, reallocate
memory, or get more memory.

Tim

-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of akshay
kulkarni
Sent: Sunday, February 6, 2022 1:56 PM
To: R help Mailing list <r-help at r-project.org>
Subject: [R] handling breaks in a for loop

[External Email]

dear members,
                         I have a very large for loop (basically a web scraping
loop) with 500 iterations(over different stocks). I am concerned about the loop
breaking midway.

My question is: is there any method to store the succesful iterations and
continue with the iteration (ofcourse, after fixing the bug) where the exception
occured? I can insert a save () function in the body of the loop and save the
succesful iterations but this would slow down the execution speed. Any other
method? I want to avoid trycatch as much as possible because an NA in the place
of a succesful iteration would cost me much.

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

        [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=F0cPNGUlUW-Cd9RJzYladHn1oypv0cPLA-d9dEO42hExw8rxis6aw3FPV6DtBQU2&s=jmZ4HPdnRH6ive_u-90RBNQQtFrnMey9AZv8MRZGQbc&ePLEASE
do read the posting guide
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=F0cPNGUlUW-Cd9RJzYladHn1oypv0cPLA-d9dEO42hExw8rxis6aw3FPV6DtBQU2&s=Tpxb0boNRBRe0_7_FZteYKLLal9zfDXAXImIExuV35o&eand
provide commented, minimal, self-contained, reproducible code.