 It's LinkedIn Learning author Monica Wahee with today's data science makeover. Watch while Monica Wahee demonstrates four different ways to run code in R. Hello everyone. The other day I got a comment on one of my R videos asking me how I was running R. It actually brought me back to the days when R GUI was new, like just invented. I actually had the same question. How do you run code? So I thought I'd just do a video to demonstrate the four different ways I know that you can run code in R GUI. You will see that I have this code window open. This code is from another video where I demonstrate box plots, but it doesn't matter. The purpose here is to demonstrate how to run code, any code. But what's important is that you can tell that this is a code file because you can see the name of it here. It's very faint, but you can see a file name and path. That's what you see on this top border of the window of code files. The reason I point that out is there is a special window and that's this one right here behind it. See this window? This says R console on the top. This is a special window. How I keep track of it is I always keep it up in the upper left because watch this. See that? Now it looks like a code window and I could just click on some code and easily lose it. No, that is a bad habit. I always keep it in the upper left. Let me put it back. Okay, so why is that console thing important? Well, it has to do with us running code. Let's go back to our demonstration code. Okay, we are just going to practice running code in R by running these two lines of code. The first line of code is a read.csv command, which just reads in a small data set called maHosp. It has data about Massachusetts hospitals. The second line that says maHosp runs the data set, so we can view the raw data in the console. Okay, so here comes our first way to run code in R. We are going to highlight this first line of code and then I'm going to right click. See the first entry? It says run line or selection. Also, look to the right of it. It says key command is control R, but we'll just remember the control R. For now, we will select run line or selection. Let's actually pay attention to what happens in R when we do that. Okay, well, we would like to believe that R read in our data set, but look literally at what happened. Choosing that menu option caused R to copy the line of code we highlighted into the console. And then also hit enter because, as you can see, we are aligned below that. Okay, so if you are used to using R and you think you just read in a data set like we just did, the first thing you want to do is look at the data set. And you can do that by just running the data set name. So I just highlighted the data set name, maHosp. And I could do the same thing I just did. Right click and choose run line or selection. But instead, I'm going to teach you the second method of running code in RGUI. And that is just typing it yourself into the console. So watch me do that. I will click on the console, type in maHosp and then hit enter. There, see that? It ran the data frame. And I'll put it to the console. Okay, so that's the second way. Hey, before I show you the third way, let's clear the console. You can also do that a few different ways I know of. From the menu, we go to edit and then choose clear console. But look, we could also choose control L. But we aren't going to do that that way. Instead, we are going to use the right click way. See clear window? That's what I'm choosing. Okay, much better. All right, are you ready for the third way to run code? You probably already guessed it. Let's highlight and run the data frame maHosp again. But this time after it's highlighted, I'm going to show you the control R way of running code. So highlight the code, go find the control key, hold it down and then type R. I do it with my left hand without even thinking. My pinky on the control key and my index finger on the R key. So here it is again. It ran. Let's clear the console again. I'm going to do it the right click way. You can do it how you like. Okay, back to our code. All right, I showed you the highlight and right click way that type directly into the console way and the control R way. The last way is the menu way. Let's again start by highlighting maHosp. This time we are going to use the regular menus. We'll go to edit and then choose run line or selection. And there it is as promised as demonstrated. Four different ways to run code in R. Thank you for watching this data science makeover with LinkedIn Learning author Monica Wahee. Remember to check out Monica's data science courses on LinkedIn Learning. Click on the link in the description. I'm so glad you found my channel and watched this video. If you found the video helpful, then please hit the like button. Please also look around my channel and if you see anything you like, subscribe. Leave a comment and tell us your favorite way to run R. And don't forget to enjoy your day.