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
wereHamster /
Created Jan 9, 2011
Script to upload files to github.
emitanaka / collapseoutput.js
Created Jul 20, 2019
Collapsible Code Output for `xaringan`
View collapseoutput.js
(function() {
var divHTML = document.querySelectorAll(".details-open");
divHTML.forEach(function (el) {
var preNodes = el.getElementsByTagName("pre");
var outputNode = preNodes[1];
outputNode.outerHTML = "<details open class='output'><summary>Output</summary>" + outputNode.outerHTML + "</details>";
(function() {
richfitz / Rd2Knitr2HTML.R
Created May 10, 2012
Convert Rd files to HTML, knit()'ing examples
View Rd2Knitr2HTML.R
opts_knit$set(progress = FALSE, verbose = FALSE)
## We need a list of files and a package to start.
args <- commandArgs(TRUE)
package <- args[[1]]
files <- args[-1]
johnmyleswhite / gist:5248212
Created Mar 26, 2013
The Joys of Sparsity: Forward Stagewise Regression
View gist:5248212
# Generate (x, y) data with a sparse set of active predictors
# prob controls the frequency of predictors having zero effect
function simulate_date(n::Integer, p::Integer, prob::Real)
x = randn(n, p)
beta = randn(p)
for j in 1:p
if rand() < prob
beta[j] = 0.0
ramhiser / find_peaks.r
Last active Apr 11, 2018
Find local maxima (peaks) in a vector
View find_peaks.r
#' Finds the local maxima (peaks) in the given vector after smoothing the data
#' with a kernel density estimator.
#' First, we smooth the data using kernel density estimation (KDE) with the
#' \code{\link{density}} function. Then, we find all the local maxima such that
#' the density is concave (downward).
#' Effectively, we find the local maxima with a discrete analogue to a second
#' derivative applied to the KDE. For details, see this StackOverflow post:
#' \url{}.
kleinschmidt /
Created Apr 17, 2013
Little shell script to streamline using knitr from the command line, or in case you want to use it with something like emacs which can call a shell script to compile a document.
# -- Dave Kleinschmidt, April 2013
# streamline knitting of Rnw files from the command line.
usage="Usage: $0 input-filename.Rnw [-nolatex] [-notangle]"
if [ $# -lt 1 ]; then
echo $usage
exit 1
kbroman / sprintf_fix.R
Created Mar 21, 2013
R function to deal with sprintf("%.2f", ...) returning -0.00
View sprintf_fix.R
# a function to deal with sprintf("%.2f", ...) returning -0.00
# see
f <- function(..., dig=2) {
g <- sprintf(paste0("%.", dig, "f"), ...)
z <- paste0("0.", paste(rep("0", dig), collapse=""))
g[g==paste0("-",z)] <- z
even4void / Makefile
Created Oct 25, 2012
A sample demo of R Markdown with pandoc
View Makefile
Rscript -e "require(knitr); require(markdown); knit('$(RMDFILE).rmd', '$(RMDFILE).md'); purl('$(RMDFILE).rmd')"
${PANDOC} --mathjax --toc -B header.html -A footer.html --bibliography refs.bib --css markdown.css -s $(RMDFILE).md -o $(RMDFILE).html
kohske / script.R
Created Jun 22, 2012
report generation by spin
View script.R
#' # Rスクリプトからレポート生成
#' # `spin`ning in knitr package
#' ### @kohske
#' Rスクリプトはこちら
#' ---
ramnathv /
Created Mar 16, 2012
GFM Table with knitr + ascii

Here is how you can make a table in GFM format using knitr + ascii

gfm_table <- function(x, ...) {
    y <- capture.output(print(ascii(x, ...), type = "org"))
    # substitute + with | for table markup
You can’t perform that action at this time.