Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Modern R Programming Cookbook

You're reading from   Modern R Programming Cookbook Recipes to simplify your statistical applications

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781787129054
Length 236 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jaynal Abedin Jaynal Abedin
Author Profile Icon Jaynal Abedin
Jaynal Abedin
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Installing and Configuring R and its Libraries 2. Data Structures in R FREE CHAPTER 3. Writing Customized Functions 4. Conditional and Iterative Operations 5. R Objects and Classes 6. Querying, Filtering, and Summarizing 7. R for Text Processing 8. R and Databases 9. Parallel Processing in R

Handling exceptions and error messages

Whenever you are creating a function, there could be a conditional statement or even some mathematical operation that might not be executable for all situations. For example, if you are transforming a numeric vector into logarithms, then a negative value will give an error. In this recipe, you will learn how to handle exceptions and errors and/or warnings while you write your own customized functions. There are several functions in R to handle exceptions/errors/warnings as follows:

  • warning(): This function can generate a warning message
  • stop(): This function can generate an error message
  • supressWarnings(expr): This function evaluates the expression inside the function and then ignores warnings if there are any
  • tryCatch(): This function (tryCatch() or try()) evaluates the code inside the parenthesis and then assigns an exception handler
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image