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 / 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 /
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

title: "Show Your Webcam in R Markdown Presentations" author: "Yihui Xie" date: "2015/10/25" output: slidy_presentation: incremental: yes duration: 40 footer: "Webcam in R Markdown, Yihui Xie, 2015" includes:

yihui / htmltools-deps.Rmd
Created Mar 31, 2015
A minimal example of HTML dependencies
View htmltools-deps.Rmd
title: HTML Dependencies
output: html_document
This example explains how HTML dependencies work in **htmltools**. Sometimes an HTML fragment may have additional dependencies to work correctly, such as JavaScript and/or CSS files. In R Markdown documents, you have to let **rmarkdown** know these dependencies, so they can be added to the HTML header when the document is rendered through Pandoc.
Another thing that you need to pay attention is you have to "protect" your HTML output so that Pandoc does not touch it, e.g. when you have four leading spaces, Pandoc may think this line is supposed to be a `<pre>` block whereas you only meant to indent the line for cosmetic purposes. In this case, the function `htmltools::htmlPreserve()` will be _automatically_ applied to your HTML content in R Markdown if the content is generated from `htmltools::tags` or wrapped in `htmltools::HTML()`.
Now we use a random CSS file in the **knitr** package to illustrate how dependencies work. The goal here is to generate a
yihui /
Last active Mar 15, 2017
A Shiny app based on annyang that responds to voice input
yihui / test.Rnw
Created Dec 23, 2013
The Rnw document that confused several people in R-help.
View test.Rnw
<<setup, include=FALSE, cache=FALSE>>=
\title{Knitr and ggplot2}
\author{Daniel Haugstvedt}
yihui / readme.Rmd
Last active Feb 10, 2020
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 / 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 / par_page.R
Created Aug 27, 2013
test par('page') which will be available in R 3.0.2
View par_page.R
stopifnot(getRversion() > '3.0.1')

These 498 packages are currently affected by the check of ::: on CRAN:

You can’t perform that action at this time.