Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:39:01+00:00 2026-06-18T00:39:01+00:00

I have a large R script of, say, 142 small sections. If one section

  • 0

I have a large R script of, say, 142 small sections. If one section fails with an error I’d like the script to continue rather than halt. The sections don’t necessarily depend on each other, but some do. If one in the middle fails that’s ok. I’d prefer not to pepper this script with try() calls. And I’d prefer not to have to split the file up into many smaller files as each section is quite short.

If source() could be made to work as if it had been copy and pasted at the R console, that would be great. Or if there was a way to downgrade error to warning, that would be fine too.

Once the script has run I intend to grep (or similar) the output for error or warning text so that I can see all the errors or warnings that have occurred, not just that it has halted on the first error.

I’ve read ?source and searched Stack Overflow’s [R] tag. I found the following similar questions, but try and tryCatch were the answers provided :

R Script – How to Continue Code Execution on Error
Is there any way to have R script continue after receiving error messages instead of halting execution?

I’m not looking for try or tryCatch for the reasons above. This isn’t for R package testing, where I’m aware of the testing frameworks and where many try() or test_that() calls (or similar) are entirely appropriate. This is for something else where I have a script as described.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:39:02+00:00Added an answer on June 18, 2026 at 12:39 am

    To make this more concrete, how about the following?

    First, to test the approach, create a file (call it "script.R") containing several statements, the first of which will throw an error when evaluated.

    ## script.R
    
    rnorm("a")
    x <- 1:10
    y <- 2*x
    

    Then parse it into a expression list, and evaluate each element in turn, wrapping the evaluation inside a call to tryCatch() so that errors won’t cause too much damage:

    ll <- parse(file = "script.R")
    
    for (i in seq_along(ll)) {
        tryCatch(eval(ll[[i]]), 
                 error = function(e) message("Oops!  ", as.character(e)))
    }
    # Oops!  Error in rnorm("a"): invalid arguments
    # 
    # Warning message:
    # In rnorm("a") : NAs introduced by coercion
    x
    # [1]  1  2  3  4  5  6  7  8  9 10
    y
    # [1]  2  4  6  8 10 12 14 16 18 20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large script that has no database connection yet. I need one
I have a program that produces large number of small files (say, 10,000 files).
I have fairly large script within an .svg file and I'd like to get
I have a very large script which contains a lot of php files, so
I have a fairly large script and am trying to find out, why $(document).on(
I have a very large script which is creating multiple views. In a number
Hello I have a very large SQL script and while trying to execute it
I have a very large php maintenance script (basically it recreates thumbnails for an
I have a PHP script that creates large complex tables. I am attempting to
I have a SQL script which is extremely large (about 700 megabytes). I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.