Skip to content

Instantly share code, notes, and snippets.

View yihui's full-sized avatar

Yihui Xie yihui

View GitHub Profile
@yihui
yihui / printfun.Rnw
Last active September 30, 2015 14:18
print highlighted source of a function
\documentclass{article}
<<insert-fun, echo=FALSE>>=
insert_fun = function(name) {
read_chunk(lines = capture.output(dump(name, '')), labels = paste(name, 'source', sep = '-'))
}
@
\begin{document}
@yihui
yihui / readme.md
Created March 5, 2012 07:09
Filling a full beamer slide with tikzDevice output from R
@yihui
yihui / NpptoR-auto-completion.R
Created March 21, 2012 03:09
An R script to generate R.xml for auto-completion in Notepad++
# this script will generate a file 'R.xml' for auto-completion in Notepad++; I
# wrote it when my programming style was pretty bad, but this script seems to be
# still functional anyway
# R.xml will be generated under your current work directory: getwd()
# load some packages to the search path:
pkg <- installed.packages()[, 'Priority']
sapply(names(pkg)[!is.na(pkg)], library, character.only = TRUE)
# you may load any installed packages here
@yihui
yihui / animation-useR2010-Xie.R
Created March 23, 2012 03:33
My Talk on Animations at useR! 2010 (NIST, Gaithersburg)
pdf.options(width = 7, height = 5, family = "AvantGarde")
library(RColorBrewer)
library(animation)
# title page
# pdf('titlepic.pdf', width=7, height=4)
ani.options(nmax = 66, interval = 0)
data(HuSpeech)
par(mar = c(4, 4, 0.1, 0.1))
@yihui
yihui / knitr-breaklines.Rnw
Created March 26, 2012 21:15
How to break lines in knitr output with the listings package
% see http://yihui.name/knitr/demo/listings/ for output
\documentclass{article}
% define a new environment to break lines for error messages
\lstnewenvironment{Serror}{\lstset{style=Routstyle,breaklines=true}}{}
<<setup, include=FALSE>>=
render_listings()
@
@yihui
yihui / readme.md
Created April 22, 2012 16:36
use a chunk option to control output width in knitr
@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)))
}