Want to keep learning?

This content is taken from the Purdue University & The Center for Science of Information's online course, Introduction to R for Data Science. Join the course to learn more.

Skip to 0 minutes and 12 seconds Now that we’ve downloaded R and got R installed, and we’ve downloaded RStudio and installed it as well, let’s go look at how to run RStudio. You’re gonna see a link to R on your desktop, but that’s just to the regular R app, so I’m not going to use that one. I’m gonna go up to my Windows link in the upper left of my screen. I’ll see RStudio under my Recently added, and more generally, I’ll see RStudio down in my list of programs here. So it says RStudio, New because I’ve just gone and installed it. So lets click on RStudio and open it.

Skip to 0 minutes and 47 seconds So once RStudio is open, one thing you might want to do is make the window a little bit larger, so that you can go and see all the different components that are available inside RStudio. You kind of notice several different parts of the RStudio interface. Going to have a part where you can type your code here and see the effect of what you type. Up in the upper right, you’re gonna have an environment portion where you’ll see any variables that you declare. And in the lower part, you’ll have this modular window that initially shows you files, but as you start plotting things, you can click on Plots, and you’ll see plots as they’re opened there.

Skip to 1 minute and 27 seconds In fact, it’ll automatically open the plot window for you as needed. You’ll see a list of packages that are installed in your R environment. You’ve even got a Help window where you can go click around in the Help interface. So, often I don’t type my R code right at the prompt. Rather what I do is I make an R file so that I can save what I’m doing as I go. Type the commands inside the file I’ll create, and then the results will appear here at the arrow. So let’s do a File > New File > R Script, and I’ll go ahead and save it. I’ll Save As, might just wanna call it Day1, for instance.

Skip to 2 minutes and 8 seconds You can call it anything you like, just call it Day1.R. Notice where I’m saving it, I’m saving it in my Documents folder. But again, you can save it anywhere you please. So you’ll notice that now I can type in this window, scroll up and down in this window. And nothing’s going to happen down here in the lower window until I type a command. So, let’s suppose for instance that I want to generate some uniform random variables. I can type runif(10), and I want to go run this command, even if I hit return or hit enter, nothing’s going to happen. One way that I can execute that command is I can move my mouse and I can hit the Run button.

Skip to 2 minutes and 53 seconds And you’ll see I get ten uniform random variables. And if I run it again, I’m gonna get more random variables only if I’m clicked on that line. Let’s do that again, if I click on line 2 and I hit Run, ten more uniform random variables. And my cursor will advance down to line 3 so that if I hit Run again, it’s not gonna run again. Now it takes a lot of time, especially when you’re typing code, to move your mouse over to the Run button and hit Run. Instead what I prefer to do is have my cursor on the line I want to run and hit Ctrl+R.

Skip to 3 minutes and 26 seconds So then I can quickly arrow back up and hit Ctrl+R again, arrow back up and hit Ctrl+R again, do that as many times as I like, without having to touch the mouse. Another thing is, I’ll often see students go to the end of the line to run the line, but that’s not necessary. You can even be in the very middle of the line and run. Again, I’m using Ctrl+R to go and run the line that I’m on. Things are gonna work really similarly on the Macintosh and I’m usually gonna work in the Macintosh environment, but I just wanted you to see how things work in R on Windows. So you’ll notice that my file hasn’t been saved.

Skip to 4 minutes and 1 second I can see that here because the file name’s in red and I have a little red star. So you can just hit the disk button to save the file, and you notice, that makes the file name become black and the star disappears. Another possibility is that you can just hit the save button. So for instance, if I ask it for 20 uniform values drawn at random, you’ll see that I made some changes to my file, so that the file name’s in red again with a star. I could click on the little disk icon to save it, or just like I hit Ctrl+R to run the line, I could hit Ctrl+S to save the file.

Skip to 4 minutes and 36 seconds That might be a little more efficient for you.

Run RStudio for the First Time


In windows, “Ctrl + Enter” will do: run the current line, then the cursor moves to the next line.
I suppose in the video, Professor Ward means ‘‘ctrl + return’’ when he says ‘‘ctrl + r’’.

– Teaching assistant

Share this video:

This video is from the free online course:

Introduction to R for Data Science

Purdue University