Skip to content

Instantly share code, notes, and snippets.

@joshbode
Last active December 14, 2015 09:18
Show Gist options
  • Select an option

  • Save joshbode/5063973 to your computer and use it in GitHub Desktop.

Select an option

Save joshbode/5063973 to your computer and use it in GitHub Desktop.
Wrapper for knitr
#!/bin/bash
# wrapper for knitr
RMD_FILE="$1"
MD_FILE="/tmp/$(basename $0).$$.md"
HTML_FILE="${RMD_FILE%.*}.html"
read -d '' COMMAND << "EOF"
library(knitr, quietly=TRUE)
library(markdown, quietly=TRUE)
knit("%s", "%s")
invisible(markdownToHTML("%s", "%s", options=c('use_xhtml')))
EOF
printf -v COMMAND "$COMMAND" "$RMD_FILE" "$MD_FILE" "$MD_FILE" "$HTML_FILE"
# collapse command by converting new-lines to semi-colons and execute
Rscript -e "${COMMAND//$'\n'/; }" && rm -f $MD_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment