Week 2 - Homework - R-Markdown
Introduction
In this homework, we'll be using git to version and share R-Markdown notebooks. This is the task that is a daily part of the BLab's standard workflow for working on a project.
An R-Markdown notebook is a type of file that mixes text with the code that is used to calculate statistics, produce tables, draw plots, etc. (code-generated elements) You then don't have to copy these elements from the software that you used to create them to the editor where you write your project reports and, ultimately, your scientific article. By eliminating this very much error-prone copying step, R-Markdown documents help you ensure that the code-generated elements are up-to-date and consistent with each other. And once you get used to working with them, you will also save yourself a lot of time and headache because updating one step in your data processing will only require you to push one button to update all the other stuff that might change as the result.
R-Markdown documents are conventionally saved with the .Rmd
extension. As a consequence, they are often referred to as `.Rmd` documents. Kind of like when we talk about sending a .docx
instead of calling it a Word document.
R-Markdown notebooks contain text and code but they don't themselves contain the numbers, plots, tables, etc. To see everything combined together, we need to render
(also called "knit") the notebook - run all the code in it, glue the code's outputs with the text, format the results, and output a file that can be directly viewed in software that knows nothing about R, RStudio, R-Markdown, etc. In Chapter 18, you'll render an .Rmd
file to .html
(files that can be viewed in a web browser) and .md
(Markdown, can be viewed on GitHub, in RStudio, and other software) formats. Other commonly used formats are .pdf
and .docx
. More on the rendering in Chapter 18.
Chapter 18
Instructions
Follow everything in the chapter with the following amendments:
In section 18.5, the instructions say "[i]nsert 1 to 3 lines of functioning code that’s relevant to you or the project where you’re experimenting." Adjust the degree of relevance to your liking; we aren't learning R here.
Section 18.6. Make sure that at least one of those chunks produces a plot. Again, while it'll be nice if the code has some relevance to your work, it doesn't have to be. The main reason we'd like you to do this is for you to practice committing the images that the Markdown (
.md
) version of your notebook uses.Check that the
.md
version of your notebook renders correctly on GitHub, including the plot(s). Then send the link to that.md
file to thegit-support
channel.
Chapter 19
In this chapter, we'll convert an .Rmd
into an R (.R
) script that can still be rendered if necessary. This is a much less common task but a good practice for git anyway.
Instructions
Follow the chapter up to section 19.2.
Section 19.2 instructs you to do
.Rmd
->R
conversion manually. Instead of that, try running the following code in the R console in RStudio substituting your notebook's name for<name-of-your-notebook>
:As the result, a
<name-of-your-notebook>.R
file should be produced. If the code doesn't work for any reason, don't spend too much time troubleshooting it - it is easier to follow the manual instructions in 19.2.After committing and pushing, and send a GitHub link to the
git-support
channel.
Follow the rest of the chapter.
Checklist
Last updated