Skip to content

Instantly share code, notes, and snippets.

@slowteetoe
Created May 12, 2015 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slowteetoe/7b8426f567ac3df1d8f9 to your computer and use it in GitHub Desktop.
Save slowteetoe/7b8426f567ac3df1d8f9 to your computer and use it in GitHub Desktop.
knitr to html
#!/bin/bash
# adapted from https://github.com/jdavis/dotfiles/blob/master/bin/knitr
# make sure the ruby gem 'kicker' is installed
# also make sure the r packages 'knitr' and 'markdown' are installed
FILE="${1}"
RMD="$FILE.Rmd"
MD="$FILE.md"
HTML="$FILE.html"
if [[ $# != 1 ]]; then
echo "Usage: knitr <Rmd_file_without_extension>"
exit
fi
if [[ ! -f "${RMD}" ]]; then
echo "Cannot find: ${RMD}"
exit
fi
hash kicker 2> /dev/null || {
echo "Please install the Ruby gem 'kicker', usually the following will work:"
echo " $ gem install kicker"
exit
}
KNITR="echo \"Rerunning Knitr...\"; Rscript -e \"library(knitr); library(markdown); knit('./${RMD}'); markdownToHTML('${MD}', '${HTML}', options=c('use_xhtml', 'base64_images')); browseURL(paste0('file://', file.path(getwd(),'${HTML}')))\""
echo "Watching ${RMD}..."
kicker -e "${KNITR}" ${RMD}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment