See https://github.com/yihui/knitr-examples/blob/master/037-graphics-hyperlink.Rnw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void reverse(double *a, int *na, double *b) | |
{ | |
int i; | |
for(i = 0; i < *na; i++) | |
b[i] = a[*na - i - 1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 参会单位 | |
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
<<insert-fun, echo=FALSE>>= | |
insert_fun = function(name) { | |
read_chunk(lines = capture.output(dump(name, '')), labels = paste(name, 'source', sep = '-')) | |
} | |
@ | |
\begin{document} |
OlderNewer