Skip to content

Instantly share code, notes, and snippets.

@lcolladotor
Created December 10, 2013 01:26
Show Gist options
  • Save lcolladotor/7884334 to your computer and use it in GitHub Desktop.
Save lcolladotor/7884334 to your computer and use it in GitHub Desktop.
Knit with knitrBoostrap using textmate
#!/usr/bin/env bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
# Source some support functions we need.
. "${TM_SUPPORT_PATH}/lib/html.sh"
. "${TM_SUPPORT_PATH}/lib/webpreview.sh"
# Get the viewer program. Any program (that works with open -a <name>) can be used,
# except 'html' which is reserved to mean the internal HTML window. This is also the
# default option.
# V=${TM_LATEX_VIEWER:-html}
V="html"
M=${TM_LATEX_MASTER:-$TM_FILEPATH}
DIR=`dirname "$M"`
FILE=`basename "${M%.*}".Rmd`
PDF="${FILE%.*}.html"
echo $FILE
echo $DIR
echo $PDF
# Switch to the right directory.
cd "$TM_PROJECT_DIRECTORY"
cd "$DIR"
# Prepare output window.
html_header 'knit html result' "$FILE"
echo '<h2>Kniting…</h2>'
SW=${TM_SWEAVE_WD:=${TM_DIRECTORY}}
echo -e "setwd('$SW');library(knitrBootstrap); knit_bootstrap('$FILE', code_style='Brown Paper', chooser=c('boot', 'code'), show_code=FALSE)" | R --vanilla --quiet | pre
# If there is output and it's newer than the current document, then we go directly to preview or link to it.
WEB_LOC="file://${DIR}/${PDF}"
WEB_LOC="${WEB_LOC//\\#/%23}"
redirect "${WEB_LOC}"
html_footer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment