A Multi-page HTML Document

knitr::opts_chunk$set(echo = TRUE)

Introduction

This is an example of a multi-page HTML document with some options shown in YAML header. See https://pagedown.rbind.io for the full documentation. The rest of this document is random text.

Random text

random_markdown = function(len = 100) {
  uri = knitr::image_uri(file.path(R.home('doc'), 'html', 'logo.jpg'))
  text = function(len) {
    trimws(paste(sample(c(letters, rep(' ', 10)), len, TRUE), collapse = ''))
  }
  id = function() paste(sample(letters, 8, TRUE), collapse = '')
  figure = function(i = id()) {
    sprintf('![(#fig:%s)The R logo.](%s){width=%d%%}', i, uri, sample(20:60, 1))
  }
  tab = paste(knitr::kable(head(mtcars[, 1:5])), collapse = '\n')
  table = function(i = id()) {
    c(sprintf('Table: (#tab:%s)A table example.', i), tab)
  }
  unlist(lapply(seq_len(len), function(i) {
    if (i %% 20 == 0) return(paste('#', text(sample(10:30, 1))))
    if (i %% 10 == 0) return(paste('##', text(sample(10:30, 1))))
    # insure some elements
    if (i == 3) return(text(50))
    if (i == 4) return(figure("md-fig"))
    if (i == 5) return(text(50))
    if (i == 6) return(table("md-tab"))
    # then random
    type = sample(1:3, 1, prob = c(.9, .03, .07))
    switch(type, text(sample(50:300, 1)), figure(), table())
  }))
}
cat(random_markdown(), sep = '\n\n')

Knitr inserted Figures and tables

Simple graphics

plot(1)

Simple tables

knitr::kable(head(mtcars, 3), caption = "A Simple table")


Try the pagedown package in your browser

Any scripts or data that you put into this service are public.

pagedown documentation built on Oct. 11, 2024, 9:08 a.m.