Skip to content

Instantly share code, notes, and snippets.

View ramnathv's full-sized avatar

Ramnath Vaidyanathan ramnathv

View GitHub Profile
@ramnathv
ramnathv / printfun.Rnw
Created February 27, 2012 14:05 — forked from yihui/printfun.Rnw
a hook to print highlighted source of a function
\documentclass{article}
<<hook-printfun, echo=FALSE>>=
knit_hooks$set(printfun = function(before, options, envir) {
if (before) return()
txt = capture.output(dump(options$printfun, ''))
## reformat if tidy=TRUE
if (options$tidy) txt = formatR::tidy.source(text = txt, output = FALSE)$text.tidy
con = textConnection(txt)
on.exit(close(con))
@ramnathv
ramnathv / gfm-table.md
Created March 16, 2012 16:08
GFM Table with knitr + ascii

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

render_gfm()
gfm_table <- function(x, ...) {
    require(ascii)
    y <- capture.output(print(ascii(x, ...), type = "org"))
 # substitute + with | for table markup
@ramnathv
ramnathv / ts_knit_.md
Created March 24, 2012 01:57
This is a test file uploaded using the rubygem gist

% Using Pandoc and knitR to Write Reproducible Documents % Ramnath Vaidyanathan % 23-Mar-2012

ro tidy = F, fig.width = 4.5, fig.height = 4.5, dev = 'Cairo_png' or

options(width = 75)
read_chunk('ext-chunks.R')
# opts_knit$set(upload.fun = imgur_upload)
@ramnathv
ramnathv / gh-pages.md
Created March 28, 2012 15:37
Creating a clean gh-pages branch

Creating a clean gh-pages branch

This is the sequence of steps to follow to create a root gh-pages branch. It is based on a question at [SO]

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" &gt; index.html
@ramnathv
ramnathv / create_sphinx_pages.md
Created March 28, 2012 16:02
Hosting Sphinx Documentation on Github

This script has been adapted from a post on LA Times

@ramnathv
ramnathv / gist:2272049
Created April 1, 2012 06:47
Shell Script to Display Directory Structure
#!/bin/sh
#######################################################
# UNIX TREE #
# Version: 2.3 #
# File: ~/apps/tree/tree.sh #
# #
# Displays Structure of Directory Hierarchy #
# ------------------------------------------------- #
# This tiny script uses "ls", "grep", and "sed" #
# in a single command to show the nesting of #
@ramnathv
ramnathv / upgrade_R.R
Created April 5, 2012 22:27
Upgrade R on Mac OS 10.5.8
# GET LIST OF INSTALLED PACKAGES
pkgs <- installed.packages(priority='NA')[,'Package']
save(pkgs, file="installed_pkgs.rda")
# Install the most recent version of R:
# Download the most recent version of R from The Comprehensive R Archive Network (CRAN)
# To wipe the old R version
rm -rf /Library/Frameworks/R.framework /Applications/R.app
rm -rf /Library/Receipts/R-*
@ramnathv
ramnathv / beamermacros.sty
Created April 7, 2012 09:17
Macros for Use with Beamer
% set slide background to a specified color
\newcommand{\setbgcol}[1]{\setbeamercolor{background canvas}{bg = #1}}
% set slide background to a specified pic
\newcommand{\setbgpic}[1]{
\usebackgroundtemplate{
\includegraphics[width=\paperwidth]{#1}
}
}
@ramnathv
ramnathv / gist:2328868
Created April 7, 2012 13:25
Modify Navigation Bar for a Sphinx Theme
{% extends "!layout.html" %}
{% block rootrellink %}
<li><a href="{{ pathto('index') }}">home</a>|&nbsp;</li>
<li><a href="{{ pathto('search') }}">search</a>|&nbsp;</li>
<li><a href="{{ pathto('contents') }}">documentation </a> &raquo;</li>
{% endblock %}
@ramnathv
ramnathv / gen_pdf.R
Created April 18, 2012 16:51
Looping Through a Data Frame with Sweave
# Generate PDF for a Pid
gen_pdf <- function(sdf){
rnw_file <- sprintf("%s.rnw", unique(sdf$Pid))
tex_file <- sub('.rnw$', '.tex$', rnw_file)
file.copy('template.Rnw', rnw_file)
Sweave(rnw_file)
tools::texi2pdf(tex_file, clean = TRUE, quiet = TRUE)
unlink(c(rnw_file, tex_file))
}