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 / 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();
@yihui
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) {
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 / install-texlive.sh
Created Apr 15, 2016
Install TeXLive on Linux
View install-texlive.sh
#!/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 / 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 / README.md
Last active Sep 3, 2019
Preview all syntax highlighting themes in knitr (HTML and LaTeX)
View README.md
@yihui
yihui / scrape-rviews.R
Created Jul 3, 2017
The R script I used to scrape the old RViews site (WordPress)
View scrape-rviews.R
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')
}
@yihui
yihui / grid-table.Rnw
Created May 25, 2012
draw a table by gridExtra in knitr
View grid-table.Rnw
\documentclass{article}
\begin{document}
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).
<<setup>>=
@yihui
yihui / readme.Rmd
Last active Mar 5, 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('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 / 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)[!is.na(pkg)], library, character.only = TRUE)
# you may load any installed packages here
@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)
You can’t perform that action at this time.