1 L01: Intro

1.1 General Introduction: Making Sure Everything Works; Getting to know R

1.2 Goals{G01}

1.4 Class

  • R Studio Interface
  • Installing libraries (packages)
  • R Notebook elements: combining prose and code
  • Converting R Notebook into different formats

1.5 Starting with our first workbook

Now, download a worksheet file (01_worksheets_familiar-with-r.Rmd.zip). Unzip it and open in RStudio. Let’s work through it!

NB: Original worksheets prepared by Lincoln Mullen, GMU (https://dh-r.lincolnmullen.com/worksheets.html)

1.6 Topics covered

  • Values
  • Variables
  • Vectors
  • Built-in functions
  • Using the documentation
  • Data frames
  • Installing and loading packages
  • Simple plots

1.7 Reference materials

1.8 Homework{HW01}

  • Complete the worksheet Getting familiar with R.
  • Generate the results into HTML or PDF (PDF is a little bit trickier).
  • Submit your homework as described below.

1.9 Common issues with homework

1.9.1 Tracing errors

Errors happen all the time. You will run into errors when you run your code. You will run into error messages when “knitting” your document — as a result, your document will not be generated. To resolve this:

  1. It is important to run each chunk of code separately to ensure that they all work. If any of the chunks throw errors, you will not be able to “knit” your documents.
  2. When you run into an error, R Markdown panel (usually in the lower left corner of RStudio interface) will tell you in which line the error occurred. You will need to fix it the same way you would in Step 1.

1.9.2 Comments / “Commenting out”

You do not want to constantly keep [re]installing libraries. So, if a library is already installed, you can “comment out” that line.

For example, the code chunk above should become:

#install.packages("historydata")
#install.packages("dplyr")

Adding # in front of a line (or a section of a line) turns it into a comment and it will not longer be executed.

1.9.3 Random errors

Think about the following two lines of code. Any issues that you can explain? (You might want to run these lines in R to get some clues)

  • `?median`
  • variable1 <- DigitalHumanities

1.10 Submitting homework{SH01}

  • Homework assignment must be submitted by the beginning of the next class;
  • Email your homework to the instructor as attachments.
    • In the subject of your email, please, add the following: 070184-LXX-HW-YourLastName-YourMatriculationNumber, where LXX is the numnber of the lesson for which you submit homework; YourLastName is your last name; and YourMatriculationNumber is your matriculation number.