Knitrbootstrap

A framework to create bootstrap styled HTML reports from knitr Rmarkdown.

Knitr Bootstrap

A framework to create bootstrap styled HTML reports from knitr Rmarkdown.

Table of Contents

Features

Examples

All the examples include a css style switch, so you can try out the various styles from bootswatch.

Installation

You can install the latest released version from CRAN.

install.packages('knitrBootstrap')

If you want to install the latest development version use the devtools package.

library(devtools)
install_github(username='jimhester', repo='knitrBootstrap')

Usage

Reports can be built within R, a Makefile, by RStudio or with Vim.

R

library(knitrBootstrap)
knit_bootstrap('file.Rmd')

Makefile

You can use the included Makefile to generate html reports from Rmd files from the command line. If you have a file file.Rmd and you want to create file.html use

#standard
make file.html

#with bootstrap style chooser
make CHOOSER=c('boot') file.html

#with code style chooser
make CHOOSER=c('code') file.html

#with both
make CHOOSER=c('boot', 'code') file.html

#standalone
make file.html
make file_inline.html

RStudio

Simply source the following code in RStudio before you knit your reports. See http://www.rstudio.com/ide/docs/authoring/markdown_custom_rendering for more information.

options(rstudio.markdownToHTML =
  function(inputFile, outputFile) {
    require(knitrBootstrap)
    knit_bootstrap_md(input=inputFile, output=outputFile)
  }
)

Vim

Using the Vim-R-Plugin put the following function in your .vimrc to create the file directly with knitr and the markdown package

function! RMakeHTML_2()
  update
  call RSetWD()
  let filename = expand("%:r:t")
  let rcmd = "require('knitrBootstrap');
    \knit_bootstrap(\"" . filename . ".Rmd\")"
  if g:vimrplugin_openhtml
    let rcmd = rcmd . '; browseURL("' . filename . '.html")'
  endif
  call SendCmdToR(rcmd)
endfunction

"bind RMakeHTML_2 to leader kk
nnoremap <silent> <Leader>kk :call RMakeHTML_2()<CR>

Pandoc

Pandoc can use the same files, but some things do not quite work due to markdown conversion differences between the markdown package and pandoc. Use at your own risk!

If your markdown filename is example.md you can use the header html

pandoc -H knitr_bootstrap.html example.md -o example.html

Styles

All of the examples include style toggles for both bootstrap and the code highlighting. The knit_bootstrap function has boot_style and code_style arguments if you want to use an alternative style by default.