Skip to content

Instantly share code, notes, and snippets.

View yihui's full-sized avatar

Yihui Xie yihui

View GitHub Profile
@yihui
yihui / grid-table.Rnw
Created May 25, 2012 22:26
draw a table by gridExtra in knitr
\documentclass{article}
\begin{document}
We can draw a table with the gridExtra package, and one problem is to
pre-determine the size of the table plot to remove the extra white
margin. Below is an example that shows you how to do it (courtesy of
baptiste auguie).
<<setup>>=
@yihui
yihui / htmltools-deps.Rmd
Created March 31, 2015 02:33
A minimal example of HTML dependencies
---
title: HTML Dependencies
output: html_document
---
This example explains how HTML dependencies work in **htmltools**. Sometimes an HTML fragment may have additional dependencies to work correctly, such as JavaScript and/or CSS files. In R Markdown documents, you have to let **rmarkdown** know these dependencies, so they can be added to the HTML header when the document is rendered through Pandoc.
Another thing that you need to pay attention is you have to "protect" your HTML output so that Pandoc does not touch it, e.g. when you have four leading spaces, Pandoc may think this line is supposed to be a `<pre>` block whereas you only meant to indent the line for cosmetic purposes. In this case, the function `htmltools::htmlPreserve()` will be _automatically_ applied to your HTML content in R Markdown if the content is generated from `htmltools::tags` or wrapped in `htmltools::HTML()`.
Now we use a random CSS file in the **knitr** package to illustrate how dependencies work. The goal here is to generate a
@yihui
yihui / knitr-alert.Rnw
Last active April 30, 2018 22:12
A collection of demos for knitr hooks
\documentclass{beamer}
\usepackage{url}
\begin{document}
<<setup, include=FALSE, tidy=FALSE, highlight=FALSE>>=
# do not use the highlight package; will do it manually
opts_chunk$set(highlight = FALSE, tidy = FALSE)
tokens = c('dlmMLE', 'dlmModReg') # a list of words to be highlighted by structure{}
knit_hooks$set(
chunk = function(x, options) {
@yihui
yihui / main.Rnw
Created April 24, 2012 02:23
use knit() with a loop to write reports for subsets of data
\documentclass{article}
\begin{document}
<<run-all, results='hide', message=FALSE>>=
library(xtable)
out = NULL
for (g in unique(mtcars$gear)) {
out = c(out, knit_child('template.Rnw', sprintf('gear-%s.tex', g)))
}
@yihui
yihui / readme.md
Last active July 13, 2017 20:53
create and download a GIF animation in Shiny

You may have to install the development version of the animation package from Github:

@yihui
yihui / README.md
Last active March 15, 2017 18:35
A Shiny app based on annyang that responds to voice input

title: "Show Your Webcam in R Markdown Presentations" author: "Yihui Xie" date: "2015/10/25" output: slidy_presentation: incremental: yes duration: 40 footer: "Webcam in R Markdown, Yihui Xie, 2015" includes:

@yihui
yihui / test.Rnw
Created December 23, 2013 22:15
The Rnw document that confused several people in R-help.
\documentclass{article}
\begin{document}
<<setup, include=FALSE, cache=FALSE>>=
library(knitr)
library(ggplot2)
@
\title{Knitr and ggplot2}
\author{Daniel Haugstvedt}
@yihui
yihui / par_page.R
Created August 27, 2013 20:48
test par('page') which will be available in R 3.0.2
stopifnot(getRversion() > '3.0.1')
par("page")
dev.off()
dev.new()
par("page")
plot(1)
par("page")
@yihui
yihui / readme.md
Last active December 21, 2015 17:08

These 498 packages are currently affected by the check of ::: on CRAN:

AER
BLCOP
BSagri
BatchExperiments
BatchJobs
BayHap
BayesFactor