Topic 0 - Interlude 2 - R Markdown
Background
What is the purpose of these notes?
- Overview of Markdown at a high level.
- Note: Lab 1 worksheet (“HW0”) is actually a really good place to start, and it gives you a template to work with. All HW assignments will be done the same way - you will be given a Markdown file in which you are to write your code and your explanations.
Useful links
For a comprehensive reference, go here: http://shiny.rstudio.com/articles/rmarkdown.html.
Go to Lab 1 - Homework 0 - see the handout here
What to do?
Markdown
- Markdown is a simple way of formatting text and data analyses. Refer to lecture week 1 \(\leftarrow\)Campuswire link.
- You will use RStudio to embed R code in Markdown as well as Python code (via the
reticulate
package). Refer to additional resources week 1 to view TA’s video on how the Python setup will work.
First you need to install and load packages
Just like every other programming language you may be familiar with, R’s capabilities can be greatly extended by installing additional “packages” and “libraries”.
To install a package, use the install.packages()
command. Here is an example:
install.packages("ggplot2")
You only need to install packages once. Once they’re installed, you may use them by loading the libraries using the library()
command. For today’s lab, you’ll want to run the following code
Code chunks
Code is written in ‘chunks’. Text is written as plain text, and it can be formatted in various ways. You should check out the first link above, which will give you a comprehensive overview.
Expectations & deliverable requirements
Professionalism is what we will strive for.
- File formats that you submit must follow course requirements, as stated in homework instructions.
- The moment you submit something other than .Rmd, .html, .pdf, your homework will be returned to you without grade.
- The moment you submit something other than .Rmd, .html, .pdf, your homework will be returned to you without grade.
- Code your write needs to be clean and clear. Add comments when necessary to explain what each line or function is doing.
- Leftover instructions:
- Points will be deducted for any text that says “insert code here” or “your answer here” in your homework submission.
- Clarity of exposition:
- Write clearly. Explain precisely. English sentences need to have correct grammar, and each sentence needs to have a purpose.
- Do not write things like “see above code; output is the answer”.
- Use of inline code chunks is required insetad of copying&pasting results of a computation. This is so that if you re-do the data analysis with new data, the entire document should be updated automatically.
- Write your homework and reports as if you are turning them into your clients at work.
- Can everyone understand the purpose?
- Is it clear what is your conclusion?
- Are all the graphics appropriately labeled?
- etc.
Appendix
The rest of this document was from an R template that was placed here by default when I created a new R-markdown document! I find it useful.
R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
speed dist
Min. : 4.0 Min. : 2.00
1st Qu.:12.0 1st Qu.: 26.00
Median :15.0 Median : 36.00
Mean :15.4 Mean : 42.98
3rd Qu.:19.0 3rd Qu.: 56.00
Max. :25.0 Max. :120.00
Including Plots
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.
License
This document is created for Math 563, Spring 2021, at Illinois Tech. While the course materials are generally not to be distributed outside the course without permission of the instructor, this particular set of notes is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.