Chapter 4 R/RStudio

4.1 Learning Objectives

  • Start up a C-MOOR RStudio compute container
  • Find and use features of RStudio: R console, help window, viewer, environment window, history.
  • Complete your first “swirl” tutorial

4.2 Introduction

Before beginning this assignment, you should have already created a SciServer account and submitted your SciServer username to your instructor. In this assignment you will learn how to set up the “C-MOOR RStudio” compute container on SciServer. You will learn the basics of how to use RStudio, and will practice doing R coding within RStudio. You will also do your first “swirl” lesson. Swirl is a set of R tutorials that run inside RStudio.

4.3 Instructions

4.3.1 Start up a “C-MOOR RStudio” compute container

  1. Open sciserver.org in a web browser and log in to your account.

Image of SciServer landing page

      a. If you’re already logged in, click “Home” in the top menu bar to return to the home page.

Image of SciServer Dashboard with Home highlighted

  1. Scroll down to the second set of boxes and click “Compute”.

Image of SciServer Dashboard with Compute highlighted

  1. Click “Create container”.

Image of the Compute page with Create Container highlighted

      a. Give your container a name. This can be anything you like, but it’s useful if it says something about the purpose of the container so that you can tell your containers apart. You could name this container “RStudio”, since you’ll be using it to access RStudio.

Image of the Compute page with Container name highlighted

      b. In the “Compute Image” drop-down menu, select “C-MOOR RStudio”.

Image of the Compute page with C-MOOR RStudio highlighted

      c. Under “Data Volumes”, check the box next to “C-MOOR Data”.

Image of the Compute page with C-MOOR Data highlighted

      d. Click “Create”. This may take a moment.

Image of the Compute page with Create button highlighted

  1. You should now see a new entry in your list of containers.

Image of the Compute page with arrows pointing at the container creation time/date, container name, and the container image name

      a. “Created At” should be a few moments ago.

      b. “Name” should be the name you chose.

      c. “Image” should be “C-MOOR RStudio”.

  1. Start your C-MOOR RStudio container by clicking on its name (whatever name you chose when you created the container). This will open in a new tab.

Image of the Compute page with the container name highlighted

      a. You should see RStudio in this new tab.

Image of RStudio screen

      b. If you see something else, you may have picked the wrong “Compute Image” from the drop-down menu.

If anything goes wrong, you can always delete your container by clicking the red “X” in the last column, and create a new container.

Image of the Compute page with an arrow pointing to the red X button

4.3.2 Complete your first swirl tutorial

  1. Watch this 90 second video tour of RStudio:
  1. If you’re not there already, go to the SciServer compute page and start up the C-MOOR RStudio container.

      a. Open sciserver.org in a web browser and log in to your account.

      b. If you’re already logged in, click “Home” in the top menu bar to return to the home page.

      c. Scroll down to the second set of boxes and click “Compute”.

      d. Start your C-MOOR container by clicking on its name.

  1. In the R console window of RStudio (bottom left, or if you have no files open, it may take up the whole left side of the screen) type these commands to start up swirl:

      a. library(swirl)

      b. swirl()

  1. Install the course, following the instructions provided by swirl:

      a. Enter your name

      b. Press ENTER

      c. Select 1, 2, or 3

      d. Install the course: “R Programming: The basics of programming in R”.

  1. Complete your first swirl lesson.

      a. Choose the “R programming” course.

      b. Choose Lesson 1 “Basic Building Blocks”.

      c. Follow the instructions provided by swirl to complete the lesson.

      d. When you get to the end, it will ask if you want credit on Coursera. Choose “No” (we are not using Coursera for this course).

  1. Congratulations! You have successfully completed the first lesson in swirl, Basic Building Blocks!

4.3.3 Managing your C-MOOR RStudio compute container

If you delete your container now, you will lose all your progress in swirl. If you need to return to any part of the tutorial later, it is a good idea to keep the container until you are sure that you’re finished using it.