adaptiveCenterCaption: Adds a centered caption to a variety of output types in...

Description Usage Arguments Value Creation notes Examples

View source: R/Rmd_helpers.R

Description

Adds a centered caption for latex pdf, html, and word (only left align works at this time) documents created using Rmarkdown. adaptiveCenterCaption() builds off of the function created using captioner::captioner(), assesses which type of output document is being called using knitr::opts_knit$get("rmarkdown.pandoc.to"), and then outputs plain markdown formating text for the chosen document type.

Usage

1
2
3
4
5
6
adaptiveCenterCaption(
  chunckName,
  caption = "",
  capFxn,
  type = knitr::opts_knit$get("rmarkdown.pandoc.to")
)

Arguments

chunckName

character string. Rmarkdown code chunk name containing the graphic to label. Passed to the name option in the function created by captioner::captioner().

caption

character string. Caption body to add to graphic. Passed to the caption option in the function created by captioner::captioner().

capFxn

character string. Name of the function created by captioner::captioner() for that graphic type.

type

character string. Type of output from the Rmarkdown knit. Likely not to be changed. Default is set to the result of knitr::opts_knit$get("rmarkdown.pandoc.to")

Value

Returns the plain text markdown code needed to create the centered caption for the specified output type.

Creation notes

First created on 2019-Mar-26 as I was exploring how to use Rmarkdown.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Define captioner function
```{r, include=FALSE}
figNum <- captioner::captioner(prefix="Fig.")
```

# Plot the figure with center alignment
```{r Plot-Caret-Price, echo=FALSE, results='hide', fig.align='center'}
qplot(carat, price, data = diamonds)
```

# Run the adaptiveCenterCaption function making sure to include results="asis" in chunk options
```{r, echo=FALSE, results="asis"}
adaptiveCenterCaption(chunckName="Plot-Caret-Price", caption = "This is caption 1", capFxn = "figNum")
```

jacpete/jpfxns2 documentation built on May 10, 2020, 9:15 p.m.