Readthedown Example

1 Quick Start

1.1 Install template package

devtools::install_github("6chaoran/readthedown")

1.2 Create Rmarkdown from template

RStudio > File > New File > R Markdown … > From Template

1.3 Added features

  1. logo options are added both inside the sidebar (logo) and main content (logo2)
  2. favicon option is added
  3. author avatar option is added
  4. admonitions to differentiate level of attention
  5. multiple columns layout to display content side by side
  6. fixed css style of details & summary

1.4 Cutsomize the template

Modify the style.css to further customize the markdown template

2 Admonitions

currently support

  • note: .adm .adm-note
  • warning: .adm .adm-warning
  • seealso: .adm .adm-seealso
  • tip: .adm .adm-tip
  • danger: .adm .adm-danger
::: {.adm .adm-note}
note

message
:::

note

message

:::{.adm .adm-warning}
warning

message
:::

warning

message

:::{.adm .adm-seealso}
warning

message
:::

seealso

message

:::{.adm .adm-tip}
tip

message
:::

tip

message

:::{.adm .adm-danger}
danger

message
:::

danger

message

3 Details/Summary

<details>
<summary>click me to view details</summary>
This is the details.
</details>
click me to view details

This is the details.

data("mtcars")
p <- hist(mtcars$mpg)
tbl <- mtcars %>%
  head() %>%
  kable()
plot(p)

4 Multiple Columns

4.1 Two Columns

cat("__column A__")

column A

plot(p)

cat("__column B__")

column B

print(tbl)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

4.2 Three Columns

cat("__column A__")

column A

plot(p)

cat("__column B__")

column B

plot(p)

cat("__column C__")

column C

print(tbl)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

5 Chunks in Loop

5.1 plots in a loop

# chunk options: results='asis'
data("mtcars")
for(i in seq(4)){
  cat(glue::glue("\n\n### Tab {i} {{-}}\n\n"))
  plot.new()
  mtcars %>%
    sample_n(500, replace = TRUE) %>%
    pull(mpg) %>%
    hist()
  cat("\n\n")
}

Tab 1

Tab 2

Tab 3

Tab 4

5.2 ggplot in a loop

# chunk options: results='asis'
data("mtcars")
for(i in seq(4)){
  cat(glue::glue("\n\n### Tab {i} {{-}}\n\n"))
  p <- mtcars %>%
    sample_n(500, replace = TRUE) %>%
    ggplot(aes(x = mpg)) +
    geom_histogram(bins = 30) 
  plot(p)
  cat("\n\n")
}

Tab 1

Tab 2

Tab 3

Tab 4

5.3 kable in a loop

# chunk options: results='asis'
data("mtcars")
for(i in seq(4)){
  cat(glue::glue("\n\n### Tab {i} {{-}}\n\n"))
  p <- mtcars %>%
    sample_n(5, replace = TRUE) %>%
    knitr::kable()
  print(p)
  cat("\n\n")
}

Tab 1

mpg cyl disp hp drat wt qsec vs am gear carb
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2

Tab 2

mpg cyl disp hp drat wt qsec vs am gear carb
Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8

Tab 3

mpg cyl disp hp drat wt qsec vs am gear carb
Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2

Tab 4

mpg cyl disp hp drat wt qsec vs am gear carb
Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4

5.4 styled kable in a loop

# chunk options: results='asis'
data("mtcars")
for(i in seq(4)){
  cat(glue::glue("\n\n### Tab {i} {{-}}\n\n"))
  mtcars %>%
    sample_n(5, replace = TRUE) %>%
    knitr::kable("html") %>%
    kable_styling("striped", position = "left") %>%
    cat()
  cat("\n\n")
}

Tab 1

mpg cyl disp hp drat wt qsec vs am gear carb
Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
Pontiac Firebird…2 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
Pontiac Firebird…5 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2

Tab 2

mpg cyl disp hp drat wt qsec vs am gear carb
Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4

Tab 3

mpg cyl disp hp drat wt qsec vs am gear carb
Ferrari Dino…1 19.7 6 145.0 175 3.62 2.77 15.5 0 1 5 6
Merc 240D 24.4 4 146.7 62 3.69 3.19 20.0 1 0 4 2
Ferrari Dino…3 19.7 6 145.0 175 3.62 2.77 15.5 0 1 5 6
Volvo 142E 21.4 4 121.0 109 4.11 2.78 18.6 1 1 4 2
Ford Pantera L 15.8 8 351.0 264 4.22 3.17 14.5 0 1 5 4

Tab 4

mpg cyl disp hp drat wt qsec vs am gear carb
Ford Pantera L 15.8 8 351.0 264 4.22 3.17 14.50 0 1 5 4
Porsche 914-2 26.0 4 120.3 91 4.43 2.14 16.70 0 1 5 2
Ferrari Dino 19.7 6 145.0 175 3.62 2.77 15.50 0 1 5 6
Maserati Bora 15.0 8 301.0 335 3.54 3.57 14.60 0 1 5 8
Hornet Sportabout 18.7 8 360.0 175 3.15 3.44 17.02 0 0 3 2