Skip to content

Instantly share code, notes, and snippets.

View yihui's full-sized avatar

Yihui Xie yihui

View GitHub Profile
@yihui
yihui / cran_check.R
Last active December 20, 2015 01:49
the packages that you will have to install in order to thoroughly check your own package
packages_for_cran_check = function(x, db = available.packages()) {
dep = function(x, ...) {
if (length(x)) unique(unlist(tools::package_dependencies(x, ...)))
}
# install these packages to run R CMD check on me
# x0 = dep(x, db, 'all')
# packages that reverse depend on me
x1 = dep(x, db, 'all', reverse = TRUE)
@yihui
yihui / server.R
Last active December 18, 2015 19:48 — forked from jcheng5/server.R
xy = matrix(0.5, 1, 2)
shinyServer(function(input, output) {
output$myplot = renderPlot({
hover = input$myplot_hover
if (!is.null(hover))
xy <<- rbind(xy, c(hover$x, hover$y))
par(mar = rep(0, 4))
plot.new()
points(xy, pch = rep(c(21, 19), c(nrow(xy) - 1, 1)))
box()
@yihui
yihui / twitter-header.Rmd
Created November 28, 2012 18:47
my twitter header image
```{r twitter, fig.height=626/72, fig.width=1252/71, dev='CairoPNG'}
par(mar = rep(0, 4))
layout(matrix(1:2), heights=c(5,1))
plot(sunspots, ann=FALSE, axes=FALSE)
plot(sunspots, ann=FALSE, axes=FALSE)
```
@yihui
yihui / pie.R
Created November 3, 2012 05:45
pie chart of estimate vs variability
library(RColorBrewer)
col = brewer.pal(3, 'Paired')[-1]
par(mfrow = c(1, 2), mar = c(0, 0, 2, 0))
pie(c(estimate = 1, variability = 1), main = 'theory', col = col)
pie(c(estimate = 1, variability = 0), main = 'reality', init.angle = 270, col = col)
@yihui
yihui / static_html.R
Created October 9, 2012 05:27
make static html help for all R packages
makeStaticHTMLHelp <- function(libs = .libPaths()) {
make.packages.html(lib.loc = libs)
links <- findHTMLlinks()
for (lib in libs) {
message('* Generating static HTML for packages in library ', lib)
for (pkg in rownames(installed.packages(lib))) {
message('** package', pkg)
pkgRdDB <- tools:::fetchRdDB(file.path(lib, pkg, 'help', pkg))
@yihui
yihui / 3rd-ChinaR-gWidgets-Yihui-Xie.R
Created February 7, 2012 01:34
talk on gWidgets at 3rd ChinaR conference
# install.packages(c('gWidgetsRGtk2', 'gWidgetstcltk', 'gWidgetsrJava'))
library(gWidgets)
## different interfaces
options(guiToolkit = 'RGtk2')
g = gwindow('RGtk2')
gtext('RGtk2', container = g)
gbutton('RGtk2', container = g)
@yihui
yihui / README.md
Last active October 7, 2015 09:57
syntax highlighter for R 2.16.0
@yihui
yihui / knitr-matlab.Rnw
Created July 15, 2012 00:28
Highlight Matlab code in knitr
\documentclass{article}
<<adjust-preamble, echo=FALSE, results='asis'>>=
if (opts_knit$get('use.highlight')) cat('\\def\\usehighlightdefs{1}\n')
@
\ifx\highlightexists\undefined
\newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.69,0.49,0}{#1}}
\newcommand{\hlesc}[1]{\textcolor[rgb]{1,0,1}{#1}}
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.75,0.01,0.01}{#1}}
\newcommand{\hlpps}[1]{\textcolor[rgb]{0.51,0.51,0}{#1}}