Created
April 11, 2016 22:08
-
-
Save fipar/c84566659425d9b5e57a6d33a6b56d9f to your computer and use it in GitHub Desktop.
knit Rmd into md and 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 | |
usage() | |
{ | |
cat <<EOF>&2 | |
usage: $0 <name> | |
knits ${name}.Rmd into ${name}.md and ${name}.html | |
EOF | |
exit | |
} | |
err() | |
{ | |
echo $* >&2 | |
exit | |
} | |
[ $# -eq 0 ] && usage | |
name=$1 | |
[ -f ${name}.Rmd ] || err "Cannot find or read ${name}.Rmd" | |
trap "rm -f /tmp/knit.$$.R" SIGINT SIGTERM | |
cat <<EOF>/tmp/knit.$$.R | |
require(knitr) | |
require(markdown) | |
knit('${name}.rmd','${name}.md') | |
markdownToHTML('${name}.md','${name}.html') | |
browseURL(paste('file:///', file.path(getwd(), '${name}.html'), sep='')) | |
EOF | |
R CMD BATCH /tmp/knit.$$.R | |
rm -f /tmp/knit.$$.R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment