1 L01: Intro
1.1 General Introduction: Making Sure Everything Works; Getting to know R
1.2 Goals{G01}
- Install R and R Studio and start working with them
- Get to know R Notebooks (R markdown)
1.3 Software
1.4 Class
- R Studio Interface
- Installing libraries (packages)
- R Notebook elements: combining prose and code
- Converting R Notebook into different formats
1.4.1 Installing rmarkdown
Instructions here: https://bookdown.org/yihui/rmarkdown/installation.html
More information on R Markdown:
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
- R Primer (https://dh-r.lincolnmullen.com/primer.html) in: Lincoln A. Mullen, Computational Historical Thinking: With Applications in R (2018–): https://dh-r.lincolnmullen.com.
- Use the this primer as a quick introduction to the
R
language, or as a reference for the rest of the course.
- Use the this primer as a quick introduction to the
- The original worksheets have been developed by Lincoln Mullen (https://dh-r.lincolnmullen.com/worksheets.html). The ones used in this class might have undergone some changes and relevant adaptations.
- Your
R
installation may ‘speak’ your main language. It is nice on one hand, but can be quite inconvenient in class, where the main language is English. You may have to do cast some spells to switchR
into English. Possible solutions can be found here: https://stackoverflow.com/questions/13575180/how-to-change-language-settings-in-r/
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:
- 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.
- 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.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
, whereLXX
is the numnber of the lesson for which you submit homework;YourLastName
is your last name; andYourMatriculationNumber
is your matriculation number.
- In the subject of your email, please, add the following:
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:
Adding
#
in front of a line (or a section of a line) turns it into acomment
and it will not longer be executed.