knitr::opts_chunk$set(echo = TRUE, prompt = TRUE, fig.align = 'center')
knitr::opts_knit$set(global.par = TRUE)

Text, bullets, links

library(knitr)

For more information see the accessr site on GitHub

Displayed equations {.smaller}

$$ \begin{eqnarray} T = \left{\begin{array}{ll} \overline{X} & \mbox{ with probability } 1 - 1/n \,, \ \overline{X} + n & \mbox{ with probability } 1/n \,. \ \end{array}\right. \end{eqnarray} $$

[ \begin{aligned} P(X \leq x) &= P(F^{-1}(U) \leq x) \ &= P(F(F^{-1}(U)) \leq F(x)) \ &= P(U \leq F(x)) = F(x). \end{aligned} ]

Tips (prompted by issues when creating Word output):

R-generated figure

oldpar <- par(mar = c(4, 4, 1, 1))
plot(1:10, 1:10, pch = 1:10, xlab = "x", ylab = "y")

External figure (png file)

include_graphics(system.file(package = "accessr", "examples", "plot.png"))

Table

The table will only appear if both of the packages dplyr or huxtable are installed. The huxtable code is hidden because it is lengthy. Of course, there are many other ways to create tables in R markdown.

got_dplyr <- requireNamespace("dplyr", quietly = TRUE)
got_huxtable <- requireNamespace("huxtable", quietly = TRUE)
got_both <- got_dplyr && got_huxtable
library(dplyr, warn.conflicts = FALSE)
library(huxtable, warn.conflicts = FALSE)
row1 <- c("1", "A", "36", "24")
row2 <- c("", "B", "24", "16")
row3 <- c("2", "A", "4", "16")
row4 <- c("", "B", "16", "64")
blank <- rep("", 4)
x <- as.data.frame(rbind(row1, row2, row3, row4))
colnames(x) <- c("clinic", "drug", "success (S)", "failure (F)")
x_hux <- x %>% 
  as_hux() %>%
  set_top_border(c(2, 4), everywhere, brdr(1, "solid", "black")) %>%
  set_right_border(everywhere, 1:3, brdr(1, "solid", "black")) %>%
  set_align(everywhere, 1:4, "center") %>%
  set_width(0.8) %>% 
  set_height(0.001) %>% 
  set_number_format(everywhere, everywhere, 0) %>% 
  set_all_padding(3) %>%
  set_outer_padding(0) %>%
  set_caption("Table caption")
x_hux    

Hiding stuff using echo

# hide = TRUE to hide certain parts 
# hide = FALSE to include them
hide <- params$hide

``{asis, echo = !hide} This text will appear only ifparams$hide = FALSE`

```{asis, echo = hide}
Setting `params$hide = TRUE` can be used to hide content

Hiding a figure using eval

``{asis, echo = hide} The figure is missing becauseparams$hide = TRUE`

```r
plot(1:10, 1:10, pch = 1:10, xlab = "x", ylab = "y")
par(oldpar)


paulnorthrop/accessr documentation built on April 17, 2025, 11:35 p.m.