From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Logic and flow control

Logic and flow control

- [Instructor] In a past session, we talked about Boolean operators. Ampersand being shorthand for AND and a vertical pipeline being shorthand for the logical OR operator. R also provides a double ampersand and a double pipeline for enhanced flow control. Let's take a look at how those work. In order to demonstrate this, I've created a function. I've called it someFunction. It's here, in line four. And, it does two things: When it runs, it prints someFunction was executed. And then, in this case, on line six, it returns TRUE. I'm going to define someFunction. And now, let's use it. In line 11, I'm going to say if FALSE, and I'm going to use the double ampersand operator. So, if FALSE AND someFunction, then print The if then statement evaluated as TRUE. Let's go ahead and run that. It doesn't return anything. Why is that? It's because of the special nature of ampersand ampersand. In line 11, R looked at the…

Contents