knitr::opts_chunk$set(
    echo      = FALSE, 
    eval      = TRUE, 

    ## output settings for PDFs
    fig.pos   = "H", 
    out.extra = "", 
    fig.show  = 'hold', 
    fig.align = 'center'
    )
# image settings for html and pdf
# [only applies to images inserted with knitr::include_graphics()]

if(knitr::is_html_output()) {
    knitr::opts_chunk$set(dpi = 72)

    } else if(knitr::is_latex_output()) {
        knitr::opts_chunk$set(out.width = "100%")
        }

Overview

Update this template with your custom content. Then create a formatted output document by pressing the Knit button in or using the Shift + Ctrl + K shortcut in R Studio.

YAML Header Options

Output Formats

Review the package documentation for more about configuring the output. In brief, you should choose one or more output formats. This template is oriented toward html, Word, or PDF output, but you can choose anything you want. Include multiple formats to knit them all at once. Delete or comment out the ones you don't need.

Some output formats allow additional configurations (table of contents, color scheme or logo, etc). See the README for more.

Other Document Options

You can set some additional properties in the header, such as output file name and location. If you don't customize these, defaults will be used. See the README for more.

Markdown

This document is written in R Markdown.

Some common markdown syntax is demonstrated below. More information is available from RStudio, among many other places.

Text Formatting

Text can easily be made italic or bold or ~~strikethrough~~ or ~subscript~ or ^superscript^.

Lists

You can make unordered lists:

You can also make ordered lists:

  1. Something
  2. A second thing
  3. Note that the numbers don't need to be correct. R Markdown will take care of numbering the list during rendering.

Code Chunks

Embed R code and results via code chunks. You can decide whether to print the code, the results, and any messages or warnings.

mean_speed <- mean(cars$speed)
mean_speed

Objects in the current environment are accessible via inline code. For example, the mean speed of the cars dataset is r mean_speed.

If you want to print the code verbatim without running it, you can do that by adjusting the chunk options:

min_speed <- min(cars$speed)
min_speed

And if you want to run code without printing it, you can do that too.

max_speed <- max(cars$speed)
max_speed

The maximum speed is r max_speed.

Images

Save image files in the images/ subdirectory. Insert them into the document like this:

![This is an image caption.](images/filename.jpg)

If you want to number and cross-reference your images or have more control over how they're displayed, insert them as R code chunks instead. Be sure to give each code chunk a unique label and a caption, as in Figure \@ref(fig:chunk-name) (set eval = TRUE):

knitr::include_graphics("images/image_name.png")

Equations

Equations can be easily inserted with standard LaTeX syntax. Inline: $y_i = \beta_0 + \beta_1x_i + \varepsilon_i$

Standalone:

$$y_i = \beta_0 + \beta_1x_i + \varepsilon_i$$

Figures and Tables

Print a formatted table with knitr::kable() and refer to it as Table \@ref(tab:cars-table):

knitr::kable(
  head(cars),
  caption = "A table with some car data." #,longtable = TRUE
  )

Tip: to allow tables to break across PDF pages, pass kable(..., longtable = TRUE).

Generate a plot and refer to it as Figure \@ref(fig:cars-figure):

plot(cars)

Citations

Citations are stored as BibTeX entries in references.bib. They can be referenced inline by BibTeX id [@rmarkdown].

Footnotes

Insert a footnote anywhere.[^my-note]

[^my-note]: Citations and footnotes will be formatted automatically when you render the document.

References



rmlane/bscContentHelpers documentation built on Jan. 30, 2024, 9:43 a.m.