return arrow  Return to Community

New UDRC report template released

By: Cory Stahle
April 3, 2019

The Utah Data Research Center (UDRC) released a template for forthcoming research reports this week. Version 1.0, released via GitHub, is available for use by any organization interested in authoring academic journal style reports. In order to generate reports with this template, some knowledge of coding in R and R Markdown is necessary. Basics of R Markdown will be discussed in this blog post, but more can be learned through this online tutorial.


FIGURE 1: REPORT TEMPLATE EXAMPLE

Click here to view PDF if not displayed below.


Accessing the template

In order to use the template you will need to download the R Studio software and several packages. The required packages are listed in the table below:


FIGURE 2: REQUIRED R PACKAGES

list of required R packages

Each of these packages, with the exception of udrcTemplates, can be downloaded inside of R Studio by typing:

install.package(“packageName”)

Once the first three packages have been installed, the udrcTemplates package can be added with the following command:

devtools::install_github(“UDRC/udrcTemplates”)

After adding the package from GitHub, the UDRC report template will be available upon creating a new R Markdown file via File -> New File -> R Markdown.


FIGURE 3: CREATING R MARKDOWN FILE BASED ON UDRC TEMPLATE

Image of choosing template in R Markdown

Using R Markdown

Each R Markdown file consists of three types of content:

  • YAML metadata
  • Text
  • Code chunks

YAML metadata

YAML metadata appears at the top of the document and is written between two sets of three dashes (see Figure 4). The purpose of this code is to adjust the underlying configuration of the document. In the UDRC template, values can be set for the title, header, author, date, abstract, and logo used. The output fields should not be adjusted or the PDF may not render properly. 


FIGURE 4: YAML METADATA IN THE TEMPLATE

Image of template

Text

Once the YAML header is ended by the second set of three dashes, the text of the article begins. Section headings are created through the use of pound signs; otherwise, text is written in the same fashion as any other word processor.


FIGURE 5: BASIC TEXT IN R MARKDOWN

Image of template

R code chunks

The last component of an R Markdown document is the ability to embed the R code. Within the text portion of a document, R code chunks can be inserted, which outputs statistical tables or graphs into the final report. R code is written between two sets of three back ticks.  


FIGURE 6: SIMPLE R CODE CHUNK

Image of template

How this template is different from a basic R Markdown file

When R Studio is installed, a few basic markdown templates are provided. The UDRC template modifies those underlying templates and adds additional functionality. This added functionality is accessed through commands inserted into the text portion of the markdown document. Figure 7 is an example of using the \twocol command to change the document to a two-column format. Figure 8 provides a list of all additional commands available through the template. 


FIGURE 7: USING TEMPLATE COMMANDS

Image of template


FIGURE 8: UDRC TEMPLATE COMMANDS

Image of template



 
About the UDRC
Our data products help communicate
complex ideas in easily understood
formats to aide interested parties
make data-informed decisions.
Utah Data Research Center
140 East 300 South
Salt Lake City, UT 84111
Email: UDRC@utah.gov