Get startedGet started for free

Early warning systems

1. Early warning systems

I think everyone would agree that it's best to get advanced notice of potential problems.

2. Early warning systems

In this chapter, we'll look at standard R techniques for notifying the user. That way, we get to avoid problems before they cause a complete failure. Also, we'll get to handle issues - and they'll always be issues - in a sensible way. Before we get going with notifications, we'll first think a little about the humble Boolean operations, TRUE and FALSE. One common short-cut is to use capital T for TRUE and capital F for FALSE. But this can lead to disaster.

3. Problem 1: TRUE and FALSE

TRUE and FALSE are very special in R. They're one of the few things we can't accidentally overwrite. For example, if we try to set TRUE equal to 5 we get an error.

4. Problem 2: TRUE and FALSE

T and F aren't protected. Now I know what you're thinking - only an ejit would overwrite T or F. Well it can happen very easily. Suppose you're calculating a value from the F density. Naturally, you would use F to store the value. Unfortunately, R treats positive values as TRUE statements, leading to potential problems!

5. Solution

We can easily side step both issues that I've mentioned. First, we get in the habit of using TRUE and FALSE and shun the T & F shot cuts. I know this means typing an extra few characters, but it's worth it. Second, to test for logical values, use the function `isTRUE()`. It works as expected when `T` is passed. But protects you against rogue numerical values.

6. Let's have a little practice

OK, let's get started with the first lot of exercises.