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 /
Created Apr 15, 2016
Install TeXLive on Linux
# you can replace $HOME with any dir
sed -i 's@\$TEXLIVEHOME@'"$HOME"'@' texlive.profile
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 / input.Rnw
Last active Jan 8, 2020
use knitr (knit2pdf) to generate a PDF report in a Shiny app
View input.Rnw
yihui / readme.Rmd
Last active Nov 21, 2019
A list of package vignettes built from knitr on CRAN
View readme.Rmd
Here is a list of package vignettes _possibly_ built with **knitr** on CRAN.
```{r fetch-pkgs, include=FALSE}
pkgs = available.packages(contrib.url('', '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 / brush-loader.html
Created Feb 11, 2012
SyntaxHighlighter Brush for the R Language
View brush-loader.html
<script type="text/javascript">
"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;
yihui / warnings.R
Created Sep 22, 2013
this shows the correct way to suppress warnings is suppressWarnings() instead of options(warn = -1) alone; similarly, you should use suppressMessages() to suppress messages
View warnings.R
options(warn = -1)
# cannot really suppress warnings from the root level
withCallingHandlers(warning("hi"), warning = function(w) {
# the warning can still be captured:
## <simpleWarning in withCallingHandlers(warning("hi"), warning = function(w) { print(w)}): hi>
# however, this always works
yihui /
Last active Sep 3, 2019
Preview all syntax highlighting themes in knitr (HTML and LaTeX)
yihui / scrape-rviews.R
Created Jul 3, 2017
The R script I used to scrape the old RViews site (WordPress)
View scrape-rviews.R
page_post_links = function(
page = 1, baseurl = '',
xpath = '//h2[@class="entry-title"]/a'
) {
html = read_html(sprintf('%s/page/%d/', baseurl, page))
xml_attr(xml_find_all(html, xpath), 'href')
yihui / grid-table.Rnw
Created May 25, 2012
draw a table by gridExtra in knitr
View grid-table.Rnw
We can draw a table with the gridExtra package, and one problem is to
pre-determine the size of the table plot to remove the extra white
margin. Below is an example that shows you how to do it (courtesy of
baptiste auguie).
yihui / NpptoR-auto-completion.R
Created Mar 21, 2012
An R script to generate R.xml for auto-completion in Notepad++
View NpptoR-auto-completion.R
# 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)[!], library, character.only = TRUE)
# you may load any installed packages here
yihui / server.R
Created Oct 31, 2012
A Shiny app for ANOVA
View server.R
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)
You can’t perform that action at this time.