Skip to content

Instantly share code, notes, and snippets.

View yihui's full-sized avatar

Yihui Xie yihui

View GitHub Profile
@yihui
yihui / readme.Rmd
Last active August 31, 2023 22:00
A list of package vignettes built from knitr on CRAN
Here is a list of package vignettes _possibly_ built with **knitr** on CRAN.
```{r fetch-pkgs, include=FALSE}
pkgs = available.packages(contrib.url('https://cran.r-project.org', 'source'))
deps = tools::package_dependencies('knitr', pkgs, which = 'all', reverse = TRUE)[['knitr']]
deps = setdiff(deps, 'R.rsp') # packages that do not use knitr
deps = sort(c(deps, 'knitr'))
```
```{r vig-list, include=FALSE, echo=FALSE, cache=TRUE, cache.extra=deps, message=FALSE, error=FALSE}
vigs = lapply(deps, function(pkg) {
@yihui
yihui / install-texlive.sh
Created April 15, 2016 19:25
Install TeXLive on Linux
#!/bin/sh
# you can replace $HOME with any dir
sed -i 's@\$TEXLIVEHOME@'"$HOME"'@' texlive.profile
wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
tar zxf install-tl-unx.tar.gz
./install-tl*/install-tl -profile texlive.profile
# texlive.tar.gz is a portable and full TeXLive package
tar zcf texlive.tar.gz -C $HOME texlive
@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 / server.R
Created October 31, 2012 19:13
A Shiny app for ANOVA
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 / README.md
Last active June 30, 2021 18:01
Preview all syntax highlighting themes in knitr (HTML and LaTeX)
@yihui
yihui / input.Rnw
Last active June 13, 2021 17:45
use knitr (knit2pdf) to generate a PDF report in a Shiny app
\documentclass{article}
\begin{document}
<<names>>=
input$firstname
input$lastname
@
\end{document}
@yihui
yihui / brush-loader.html
Created February 11, 2012 22:53
SyntaxHighlighter Brush for the R Language
<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();
@yihui
yihui / warnings.R
Created September 22, 2013 04:05
this shows the correct way to suppress warnings is suppressWarnings() instead of options(warn = -1) alone; similarly, you should use suppressMessages() to suppress messages
options(warn = -1)
# cannot really suppress warnings from the root level
withCallingHandlers(warning("hi"), warning = function(w) {
print(w)
})
# the warning can still be captured:
## <simpleWarning in withCallingHandlers(warning("hi"), warning = function(w) { print(w)}): hi>
# however, this always works
@yihui
yihui / dco.txt
Last active September 22, 2020 21:00
Developer's Certificate of Origin 1.1
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
@yihui
yihui / scrape-rviews.R
Created July 3, 2017 19:07
The R script I used to scrape the old RViews site (WordPress)
library(xml2)
page_post_links = function(
page = 1, baseurl = 'https://www.rstudio.com/rviews',
xpath = '//h2[@class="entry-title"]/a'
) {
html = read_html(sprintf('%s/page/%d/', baseurl, page))
xml_attr(xml_find_all(html, xpath), 'href')
}