Created
May 12, 2015 15:05
-
-
Save slowteetoe/7b8426f567ac3df1d8f9 to your computer and use it in GitHub Desktop.
knitr to html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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