Course Outline

list High School / Advanced Statistics and Data Science I (ABC)

Book
  • High School / Advanced Statistics and Data Science I (ABC)
  • High School / Statistics and Data Science I (AB)
  • High School / Statistics and Data Science II (XCD)
  • High School / Algebra + Data Science (G)
  • College / Introductory Statistics with R (ABC)
  • College / Advanced Statistics with R (ABCD)
  • College / Accelerated Statistics with R (XCD)
  • CKHub: Jupyter made easy

Using R In the Real World (R and RStudio)

The Jupyter notebooks platform, and related platforms such as Deepnote, are wonderful tools. They are authentic as well, used by practicing statisticians and data scientists. However, if you get more deeply into R and data analysis, you probably will want to install RStudio so you can run R on your own computer.

What is RStudio?

RStudio is the most widely used IDE (or Integrated Development Environment) for programming in R. It is an application that installs on your computer like other Mac or Windows applications. RStudio is a full-featured application with lots to learn. But it’s not too hard to get started.

Installing RStudio

There are two steps to installing RStudio. Step 1 is to install R on your computer. R is a programming language that runs on your computer system. You need to install R before you can install RStudio. Step 2 is to install RStudio. RStudio is a graphical user interface (or GUI) for R. It is a Mac or Windows application that makes it easier to program and run R. In this sense it is kind of like Jupyter notebooks, but running on your computer instead of in the cloud.

To install both R and RStudio, go to this website: https://posit.co/download/rstudio-desktop/. It will walk you through the steps.

Setting Up Your R Workspace

Once you complete the two steps above, you will have “base R” and RStudio installed. In this textbook, however, we don’t just use base R. We install additional R packages that provide helpful functions (e.g., gf_point() and favstats() are not part of base R). The packages we use include:

To ease your transition into using RStudio, it’s a good idea to install these packages into your instance of R so the functions and commands you have been using will work! Once you have installed the packages, you must then load the packages with a library call (e.g., library(coursekata)) when you want to use them. We’ll go over this in the next two sections.

Installing Packages

You’ve possibly installed packages before in a Jupyter notebook using the install.packages() function. You can use this function in RStudio as well to both download and install packages. But if you’ve opened RStudio for the first time, you may be wondering, “Where do I enter the code?”

The RStudio interface has four different windows; see this brief overview of the RStudio interface. For now, we’ll just tell you that the window in the upper left is called the Source.

RStudio's windows.

You can type or paste R code into the Source window and press Run (up at the top). This will run everything in Source. The output will typically show up in the windows below (e.g., Console).

An easy way to install all the packages you need is to copy and paste the code below into the Source window, then press Run.

options(Ncpus = max(1L, parallel::detectCores() - 1), warn = 2)

install.packages("remotes")

remotes::install_github(c(
  "coursekata/fivethirtyeightdata",
  "coursekata/Lock5withR",
  "coursekata/testwhat"
))

remotes::install_cran(c(
  "coursekata",
  "fivethirtyeight",
  "ggpubr",
  "gridExtra",
  "lme4",
  "plotly",
  "statmod"
))

Note that when you run the code above, R might install other packages as well. The other packages are dependencies meaning that the packages you want to install need them to function.

Loading Packages

Each time you start a Jupyter notebook, you probably ran library(coursekata). In RStudio as well, whenever you need a package, you will need to call the library() function to get it loaded up.

Delete the code from the Source window you used to install all the packages, then copy and paste this familiar bit of code into the Source window and press Run.

library(coursekata)
favstats(~ Thumb, data = Fingers)

More About R and RStudio

This is just the beginning of your R and RStudio journey. There are many wonderful resources to take you further in your study of R. Here is a repository of them curated specifically for beginners. We hope you’ll take advantage of them!

Responses