Skip to content

Instantly share code, notes, and snippets.

📖
Writing a book

Yihui Xie yihui

📖
Writing a book
Block or report user

Report or block yihui

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yihui
yihui / cos-thumbnail.r
Created Nov 24, 2010
生成统计之都主站的占位缩略图
View cos-thumbnail.r
## setwd('path/to/magnificent/images/noimage')
set.seed(123)
png("thumbnail%d.png", width = 73, height = 73)
par(mar = rep(0, 4), ann = FALSE, xaxt = "n", yaxt = "n")
hist(rnorm(100), main = "", col = heat.colors(8))
boxplot(list(rnorm(100), runif(100)), col = 2:3)
sunflowerplot(iris[, 1:2], pch = 20, col = "gold", size = 1/20)
@yihui
yihui / check_R_version.R
Created Feb 9, 2011
check the version of R on CRAN
View check_R_version.R
x = readLines("http://cran.r-project.org/sources.html")
# the version number is in the next line of 'The latest release'
rls = x[grep("latest release", x) + 1L]
newver = gsub("(.*R-|\\.tar\\.gz.*)", "", rls)
oldver = paste(getRversion(), collapse = ".")
# new version available?
compareVersion(newver, oldver) == 1L
@yihui
yihui / kde2d-gwidgets.R
Created Dec 13, 2011
change the binwidth of 2D KDE with rgl and gWidgets
View kde2d-gwidgets.R
## adpated from demo('bivar') in rgl
rgl.demo.bivar = function(x, y, bw, ngrid = 25, ...) {
library(MASS); library(rgl)
n = length(x)
denobj = kde2d(x, y, bw, n = ngrid)
den.z = denobj$z; xgrid = denobj$x; ygrid = denobj$y
bi.z = dnorm(xgrid) %*% t(dnorm(ygrid))
zscale = 20; clear3d()
spheres3d(x, y, rep(0, n), radius = 0.1, color = "#CCCCFF")
surface3d(xgrid, ygrid, den.z * zscale, color = "#FF2222", alpha = 0.5)
@yihui
yihui / highlight-to-css.R
Created Jan 17, 2012
Turn Andre Simon's highlight themes to CSS files for knitr
View highlight-to-css.R
## put Simon's theme files under ./themes-andre/, and CSS files under ./themes/
## then run generate_css()
## author: Ramnath Vaidyanathan
#' Parses theme files from Highlight v3.06 by Andre Simon
#'
#' @param theme_name name of the theme to parse
#' @return a list containing the theme specifications
theme_to_list <- function(theme_name){
theme <- readLines(sprintf('themes-andre/%s.theme', theme_name))
@yihui
yihui / reverse.c
Created Feb 7, 2012
a C function for demo purpose
View reverse.c
void reverse(double *a, int *na, double *b)
{
int i;
for(i = 0; i < *na; i++)
b[i] = a[*na - i - 1];
}
@yihui
yihui / 3rd-ChinaR-gWidgets-Yihui-Xie.R
Created Feb 7, 2012
talk on gWidgets at 3rd ChinaR conference
View 3rd-ChinaR-gWidgets-Yihui-Xie.R
# 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 / ChinaR-Conference-Intro-2008-Yihui-Xie.R
Created Feb 7, 2012
R scripts used in the 1st China R conference
View ChinaR-Conference-Intro-2008-Yihui-Xie.R
# 参会单位
x = c(2, 1, 3, 2, 1, 1, 2, 2, 2, 3, 1, 2, 2, 2, 2,
1, 1, 1, 1, 4, 2, 2, 3, 1, 1, 2, 2, 2, 2, 3, 1, 1, 3, 1,
1, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 3, 1, 2, 1, 2, 3, 1, 2,
1, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 3, 1, 1, 1, 2, 2,
1, 1, 1, 1, 1, 3, 1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 3, 2, 2,
2, 3, 1, 2, 2, 3, 2, 1, 3, 2, 1, 1, 1, 1, 2, 2, 1, 3, 3,
1, 1, 1, 2, 1, 2, 2, 1, 3, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1,
2, 2)
# pdf("institute.pdf", width = 7, height = 3, family = "GB1")
@yihui
yihui / footprint.R
Created Feb 7, 2012
draw footprints for fun...
View footprint.R
foot = function(x, y, ...) {
points(x, y, cex = 10, ...)
points(x, y + 2, cex = 5, ...)
points(x - 0.4, y + 1.2, cex = 7, ...)
points(x + 0.4, y + 1.2, cex = 4, ...)
}
for (j in 1:3) {
x = sample(seq(1, 30, 3))
plot(x)
for (i in 1:10) {
@yihui
yihui / knitr-beamer2.Rnw
Created Feb 11, 2012
Another minimal beamer example for knitr
View knitr-beamer2.Rnw
% this is a simplified version of
% https://github.com/yihui/knitr/blob/master/inst/examples/knitr-beamer.Rnw
\documentclass{beamer}
\begin{document}
<<setup, include=FALSE>>=
# smaller font size for chunks
opts_chunk$set(size = 'footnotesize')
@
\title{A Minimal Demo of knitr}
\author{Paul Hiemstra \and Yihui Xie}
@yihui
yihui / brush-loader.html
Created Feb 11, 2012
SyntaxHighlighter Brush for the R Language
View brush-loader.html
<script type="text/javascript">
SyntaxHighlighter.autoloader(
"r  path/to/your/syntaxhighlighter/scripts/shBrushR.js",
"plain  path/to/your/syntaxhighlighter/scripts/shBrushPlain.js",
"sql  path/to/your/syntaxhighlighter/scripts/shBrushSql.js",
"js  path/to/your/syntaxhighlighter/scripts/shBrushJScript.js",
"html xml  path/to/your/syntaxhighlighter/scripts/shBrushXml.js"
);
SyntaxHighlighter.defaults["toolbar"] = false;
SyntaxHighlighter.all();
You can’t perform that action at this time.