How to Debug R Script with tryCatch Function (Example Code)

In this article, I’ll explain how to debug R codes using the tryCatch function in the R programming language.

Example: Handling Error Message with tryCatch() Function in R

tryCatch(                     # Using tryCatch() function
  
  expr = {                    # Setting up the expression
    "five" * "seven"
    message("No Errors.")
  },
 
  error = function(e){        # Error message that should be returned
    message("ERROR!!!")
  }
)
# ERROR!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top