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 / input.Rnw
Last active Sep 7, 2019
use knitr (knit2pdf) to generate a PDF report in a Shiny app
View input.Rnw
\documentclass{article}
\begin{document}
<<names>>=
input$firstname
input$lastname
@
\end{document}
@yihui
yihui / cran_check.R
Last active Dec 20, 2015
the packages that you will have to install in order to thoroughly check your own package
View cran_check.R
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 / readme.md
Last active Jul 13, 2017
create and download a GIF animation in Shiny
View readme.md
View 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 Nov 28, 2012
my twitter header image
View twitter-header.Rmd
```{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 Nov 3, 2012
pie chart of estimate vs variability
View pie.R
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 / server.R
Created Oct 31, 2012
A Shiny app for ANOVA
View server.R
library(shiny)
shinyServer(function(input, output) {
# Make three independent, repeatable copies of rnorm so that the underlying
# random values don't change
rnorm1 = repeatable(rnorm)
rnorm2 = repeatable(rnorm)
rnorm3 = repeatable(rnorm)
@yihui
yihui / static_html.R
Created Oct 9, 2012
make static html help for all R packages
View static_html.R
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 / README.md
Last active Sep 3, 2019
Preview all syntax highlighting themes in knitr (HTML and LaTeX)
View README.md
@yihui
yihui / README.md
Last active Oct 7, 2015
syntax highlighter for R 2.16.0
View README.md
You can’t perform that action at this time.