[R] handling breaks in a for loop

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Sun Feb 6 20:27:11 CET 2022


Perhaps a more conventional division of functional concerns should be applied? Separate collection of data from computation. Input functions should do input, analysis functions should do analysis, and output functions should do output... effectively lowering the cost of failure. If your first stage is simply storing the webscraped data, restarting should be easy.

On February 6, 2022 11:03:19 AM PST, "Ebert,Timothy Aaron" <tebert using ufl.edu> wrote:
>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 using r-project.org> On Behalf Of akshay kulkarni
>Sent: Sunday, February 6, 2022 1:56 PM
>To: R help Mailing list <r-help using 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 using 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&e=
>PLEASE 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&e=
>and provide commented, minimal, self-contained, reproducible code.
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list