
Earth Data Analytics Online Certificate
In the previous tutorials we’ve learned about the format and how to create a report using in . In this tutorial, we will render or an document to a web friendly, format using the package. can be used to convert files to many different formats including: , , GitHub markdown () and more.
Learning Objectives
At the end of this lesson, you will:
- Be able to produce () an file from an file.
- Know how to modify chuck options to change what is rendered and not rendered on the output file.
What You Need
You will need the most current version of and, preferably, loaded on your computer to complete this tutorial. You will also need an document that contains a header, code chunks and markdown segments.
Download lesson data
Install R Packages
- knitr:
- rmarkdown:
What is Knitr?
is the package that we use to convert an document into another, more user friendly format like or .
The package allows us to:
- Publish & share preliminary results with collaborators.
- Create professional reports that document our workflow and results directly from our code, reducing the risk of accidental copy and paste or transcription errors.
- Document our workflow to facilitate reproducibility.
- Efficiently change code outputs (figures, files) given changes in the data, methods, etc.
The package was designed to be a transparent engine for dynamic report generation with – Yihui Xi – knitr package creator
When To Knit: Knitting is a useful exercise throughout your scientific workflow. It allows you to see what your outputs look like and also to test that your code runs without errors. The time required to knit depends on the length and complexity of the script and the size of your data.
How to Knit
To knit in , click the Knit pull down button. You want to use the Knit HTML option for this lesson.
When you click the Knit HTML button, a window will open in your console titled R Markdown. This pane shows the knitting progress. The output ( in this case) file will automatically be saved in the current working directory. If there is an error in the code, an error message will appear with a line number in the R Console to help you diagnose the problem.
Data tip: You can run from the command prompt using: .
View the Output
When knitting is complete, the file produced will automatically open.
Notice that information from the header (title, author, date) is printed at the top of the HTML document. Then the shows the text, code, and results of the code that you included in the document.
Challenge Activity
Add the code below to your document. Then to format.
When you your file to , the plot you produce should look like the one below. Not so pretty, eh? Don’t worry - we will learn more about plotting in a later tutorial!
Where is the File?
In the steps above, we downloaded a file. However, where did that file go on your computer? Let’s find it before we go any further.
Is the file there?
 
-