Using this template

Basics

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. This template uses the Multi-part report template from the reportMD package, which is designed to produce a series of interconected HTML documents.

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:

data(mtcars)

Figures and Figure labels

You can also embed plots, for example:

**Figure 1:** An example plot (Download as [PDF](skeleton_files/figure-html//examplePlot-1.pdf))

Figure 1: An example plot (Download as PDF)

Figure 1: An example plot (Download as PDF)

Note that a figure label (by default this is Figure N) is added to the figure caption when the plot is included in the output. This plot can be referenced in the text by including a call to the figRef function using the the chunk label as its only argument. This is a reference to Figure 1. The reportMD package supports the use of interactive plots in HTML pages (generated with plotly) as well static versions. This feature relies on the use of ggplot2 for plotting. Using the plotMD function to produce the plot from a grob prepared earlier allows seamless switching between the two by setting the fig_format option, either globally (in the YAML frontmatter or in the call to render), via a call to knitr::opts_chunk$set or in the options for an individual chunk. Please note that the interactive version of a figure is only shown on devices with sufficient resolution. On low resolution screens (or in small browser windows) a static version of the plot will be displayed instead.

**Figure 2:** Static version of [Figure 1](#fig:examplePlot) (Download as [PDF](skeleton_files/figure-html//staticPlot-1.pdf))

Figure 2: Static version of Figure 1 (Download as PDF)

Controlling Figure size

The size of generated figures can be controlled via the fig_width and fig_height options. These work in the YAML header, where they will set the default size for all figures in the document, as well as in the options for an individual figure chunk. In either case fig_width and fig_height should be specified in inches.

By default the output document will display thumbnails of figures on screens that are at least 992px wide. The default for these thumbnails is to be half the width of the main text. To change the size of the thumbnails set thumbnail_size in the YAML header to a value between 1 and 12, where 12 corresponds to the width of the main text. The size of the thumbnail for an individual figure can be changed by setting the bootstrap.thumbnail.size chunk option. To disable thumbnails entirely, set thumbnail: false in the YAML header or bootstrap.thumbnail=FALSE in the chunk options.

Appearance of Figure lables

A number of options are available to modify the appearance of figure lables. The default appearance (Figure N: Some caption) can be changed by setting the figcap_prefix, figcap_sep and figcap_prefix_highlight options in the YAML header. These control the prefix (‘Figure’), separator (‘:’) and highlighting (bold) of the figure label respectively. For example, to change figure labels to the form ‘Fig. N:’, set figcap_prefix to ‘Fig.’ and figcap_prefix_highlight to ’*’.

Tables

Tables can be added to the output document by printing a data.frame or matrix using printMD. Use the tab.cap chunk option to provide a table caption.

Table 1: A subset of the mtcars dataset (download).

 mpghpcyl
Mazda RX4211106
Mazda RX4 Wag211106
Datsun 71022.8934
Hornet 4 Drive21.41106
Hornet Sportabout18.71758

It sometimes is desirable to provide access to the data displayed in the table. If a table chunk contains an option of the form download="variable_name", a file containing the the data stored in variable_name will be created and a download link pointing to that file will be added to the table caption.

Tables can be referenced in the same way as figures, using the tabRef function. This is a reference to Table 1.

MathJax

MathJax does work with this custom template so you can insert any LaTeX expression you want.
Here we just use a random formula to demonstrate that everything is working. Check this link for a briew overview of basic LaTeX commands.

\[ nri_{B1,B2}=\frac{R_{B1}-R_{B2}}{R_{B1}+R_{B2}} \] ## Inline R code This document format attempts to format output from inline code to be easily readable and consistent without requireing careful formatting at the time of writing. For example, this is a large number: 10,000, this one is even larger: \(3\times 10^{6}\). Here is a small one: \(10^{-6}\). \(\pi\) is approximately 3.14. The number of significant digits displayed can be controlled via pander’s digits option (which this document set to 3). If higher accuracy is desired for a specific number this can be achieved by passing it through printMD directly. A petter approximation of \(\pi\) is given by 3.141592654.

Using R objects from child documents

Your R chunks may use objects created by a chunk in a different (child) document, provided the generating chunk is cached and the cache is available when this document is knitted. To do this, simply list the path to the child document in the YAML header under the output options:

output:
  reportMD::multi_document:
    depends:
      part1: part1.Rmd
      part2: part2.Rmd

This will load all R objects generated by cached chunks in part1.Rmd into the environment in which the chunks of this document are evaluated. To only load a subset of chunks from the child document, provide a list of chunk labels:

output:
  reportMD::multi_document:
    depends:
      part2: 
        part2.Rmd: [regression, prepRegPlot]

Sometimes it may be preferable not to load R objects from other documents directly into the global environment. To load dependencies into a separate environment for each child document, add the use_namespace option:

output:
  reportMD::multi_document:
    depends:
      part2: 
        part2.Rmd: [regression, prepRegPlot]
    use_namespace: true

Now objects form part2.Rmd are accessible as part2$object_name (instead of simply object_name). This helps to avoid name clashes between objects imported from different documents.

Eiter way, we have direct access to the R objects created in the child documents and can use them in the main document in whatever order is most useful to explain the analysis and discuss the results. In part2.Rmd we constructed a ggplot and cached the resulting object. This can now be used to produce the plot here (Figure 3).

Note that some care is necessary when reproducing plots from child documents. If the plot is not self contained, i.e. it references local variables from the envirnment where it was created, the chunks containing the relevant variables have to be specified as dependencies. If use_namespace is set it is also necessary to provide the environment corresponding to the child document to plotMD.

plotMD(part2$reg_fig, envir=part2)

**Figure 3:** Linear regression result. Car weight is a good predictor for MPG and the US built cars in the dataset tend to be heavier. (Download as [PDF](skeleton_files/figure-html//regression-1.pdf))

Figure 3: Linear regression result. Car weight is a good predictor for MPG and the US built cars in the dataset tend to be heavier. (Download as PDF)

In addition to specifying all chunks to import from a child document it is also possible to specify required chunks as part of the dependson chunk option by providing dependencies of the form ‘child label:chunk label’. For example, to load the regression chunk from part2.Rmd (to which we have assigned the label part2) we could add dependson='part2:regression' to the chunk options. This has the advantage that dependencies are managed for each chunk, making it easier to update dependencies as the requirements of a code chunk change. It also makes it more explicit where objects in a code chunk come from.

Linking to child documents

It may be useful to add links to the child documents in appropriate places throughout the text. This can be achieved using pandoc’s reference link syntax. For example, to link to Part 2 simply use [some text][part2]. Links to all document dependencies listed in the header will be added to the Related Documents section of the appendix.

It is possible to link to specific parts of a child document by using the corresponding dependency object directly.

deps <- knitr::opts_knit$get('dependencies')

Printing a dependency object (via printMD) will insert a reference to the corresponding output document in the text. The optional target argument to printMD allows to specify any anchor for the link. This can correspond to a heading, e.g. see the Introduction of Part 1, or a code chunk (details of the regression model used in Part 2).

It is also possible to link to a figure or table in a child document by providing the corresponding label from the list of dependencies to indicate the target file: Part 2, Figure 1.

Appendix

Custom Functions

## Custom functions used in the analysis should go into this chunk.
## They will be listed in their own section of the appendix.

Configuration

## This chunk should contain global configuration commands.
## Use this to set knitr options and related things. Everything
## in this chunk will be included in an appendix to document the
## configuration used.

## Pander options
panderOptions("digits", 3)
panderOptions("table.split.table", 160)

Version

Document version

Fri Mar 17 13:48:12 2017

Session Info

  • platform:

    • version: R version 3.3.1 (2016-06-21)
    • system: x86_64, mingw32
    • ui: RTerm
    • language: (EN)
    • collate: English_Australia.1252
    • tz: Australia/Sydney
    • date: 2017-03-17
  • packages:

    package*versiondatesource
    assertthat0.12013-12-06CRAN (R 3.3.1)
    backports1.0.52017-01-18CRAN (R 3.3.2)
    base64enc0.1-32015-07-28CRAN (R 3.3.0)
    callr1.0.0.90002017-02-16Github (mangothecat/callr@c02300a)
    codetools0.2-142015-07-15CRAN (R 3.3.1)
    colorspace1.3-22016-12-14CRAN (R 3.3.2)
    colourpicker0.32016-12-05CRAN (R 3.3.2)
    crosstalk1.0.02016-12-21CRAN (R 3.3.2)
    DBI0.62017-03-09CRAN (R 3.3.3)
    devtools1.12.02016-06-24CRAN (R 3.3.1)
    digest0.6.122017-01-27CRAN (R 3.3.2)
    dplyr0.5.02016-06-24CRAN (R 3.3.1)
    evaluate0.102016-10-11CRAN (R 3.3.2)
    ggplot2*2.2.1.90002017-03-16Github (tidyverse/ggplot2@08e135e)
    gtable0.2.02016-02-26CRAN (R 3.3.1)
    htmltools0.3.52016-03-21CRAN (R 3.3.1)
    htmlwidgets0.82016-11-09CRAN (R 3.3.2)
    httpuv1.3.32015-08-04CRAN (R 3.3.2)
    httr1.2.12016-07-03CRAN (R 3.3.1)
    jsonlite1.32017-02-28CRAN (R 3.3.3)
    knitr*1.15.12016-11-22CRAN (R 3.3.2)
    labeling0.32014-08-23CRAN (R 3.3.0)
    lazyeval0.2.02016-06-12CRAN (R 3.3.1)
    magrittr1.52014-11-22CRAN (R 3.3.1)
    memoise1.0.02016-01-29CRAN (R 3.3.1)
    mime0.52016-07-07CRAN (R 3.3.1)
    miniUI0.1.12016-01-15CRAN (R 3.3.2)
    munsell0.4.32016-02-13CRAN (R 3.3.1)
    pander*0.6.02015-11-23CRAN (R 3.3.1)
    plotly*4.5.6.90002017-02-16Github (ropensci/plotly@cbf5885)
    plyr1.8.42016-06-08CRAN (R 3.3.1)
    purrr0.2.22016-06-18CRAN (R 3.3.2)
    R62.2.02016-10-05CRAN (R 3.3.2)
    Rcpp0.12.92017-01-14CRAN (R 3.3.2)
    reportMD*0.4.02017-02-28local
    rmarkdown1.32016-12-21CRAN (R 3.3.2)
    rprojroot1.22017-01-16CRAN (R 3.3.2)
    scales0.4.12016-11-09CRAN (R 3.3.2)
    shiny1.0.02017-01-12CRAN (R 3.3.2)
    stringi1.1.22016-10-01CRAN (R 3.3.2)
    stringr1.2.02017-02-18CRAN (R 3.3.3)
    tibble1.22016-08-26CRAN (R 3.3.1)
    tidyr0.6.12017-01-10CRAN (R 3.3.2)
    viridisLite0.1.32016-03-12CRAN (R 3.3.2)
    withr1.0.22016-06-20CRAN (R 3.3.1)
    xml21.1.12017-01-24CRAN (R 3.3.2)
    xtable1.8-22016-02-05CRAN (R 3.3.2)
    yaml2.1.142016-11-12CRAN (R 3.3.2)

Downloads

FileDescription
Table 1A subset of the mtcars dataset.

Created with reportMD