-
-
Save hsigrist/7e07f349f5d41e68f5f9 to your computer and use it in GitHub Desktop.
Revisions
-
chlalanne revised this gist
Nov 10, 2013 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,8 +19,6 @@ OPTIONS: EOF } while getopts ":hcbt" o; do case $o in h) -
chlalanne revised this gist
Nov 10, 2013 . 2 changed files with 71 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,23 @@ (insert "```\n") (previous-line))) (defun rmarkdown-weave-file () "Run knitr on the current file and weave it as MD and HTML." (interactive) (shell-command (format "knit.sh -c %s" (shell-quote-argument (buffer-file-name))))) (defun rmarkdown-tangle-file () "Run knitr on the current file and tangle its R code." (interactive) (shell-command (format "knit.sh -t %s" (shell-quote-argument (buffer-file-name))))) (defun rmarkdown-preview-file () "Run knitr on the current file and display output in a browser." (interactive) (shell-command (format "knit.sh -b %s" (shell-quote-argument (buffer-file-name))))) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,65 @@ # Process R Markdown file and display HTML output directly in the browser. # usage() { cat << EOF Usage: $0 [-h] [-c] [-b] [-t] filename This script weaves and tangles an R Markdown file using knitr. OPTIONS: -h show this message -c compile Rmd file to Markdown and HTML -b compile Rmd file and display HTML file in browser -t tangle Rmd file EOF } #usage() { echo "Usage: $0 [-c] [-b] [-t] filename" 1>&2; exit 1; } while getopts ":hcbt" o; do case $o in h) usage exit 1 ;; c) compile=1 ;; b) browser=1 ;; t) tangle=1 ;; *) usage ;; esac done shift $((OPTIND-1)) if [ -r "$1" ]; then mdfile="$1" mdfile="${mdfile%.*}" # remove extension if [[ $compile = 1 ]]; then ( Rscript -e "require(knitr); require(markdown); knit('${mdfile}.rmd', quiet=TRUE); \ markdownToHTML('${mdfile}.md', '${mdfile}.html')" ) > /dev/null 2>&1 fi if [[ $browser = 1 ]]; then ( Rscript -e "require(knitr); require(markdown); knit('${mdfile}.rmd', quiet=TRUE); \ markdownToHTML('${mdfile}.md', '${mdfile}.html'); browseURL('${mdfile}.html')" ) > /dev/null 2>&1 fi if [[ $tangle = 1 ]]; then ( Rscript -e "require(knitr); purl('${mdfile}.rmd')" ) > /dev/null 2>&1 fi else exit 0 fi -
chlalanne created this gist
Nov 10, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)) (add-to-list 'auto-mode-alist '("\\.Rmd\\'" . markdown-mode)) (add-to-list 'auto-mode-alist '("\\.rmd\\'" . markdown-mode)) (add-hook 'markdown-mode-hook 'turn-on-outline-minor-mode) (defun rmarkdown-new-chunk (name) "Insert a new R chunk." (interactive "sChunk name: ") (insert "\n```{r " name "}\n") (save-excursion (newline) (insert "```\n") (previous-line))) (defun rmarkdown-preview-file () "Run knitr on the current file and display output in a browser." (interactive) (shell-command (format "knit.sh %s" (shell-quote-argument (buffer-file-name))))) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ #! /usr/bin/env sh # # Process R Markdown file and display HTML output directly in the browser. # if [ -r "$1" ]; then mdfile="$1" mdfile="${mdfile%.*}" # remove extension Rscript -e "require(knitr); require(markdown); knit('${mdfile}.rmd', quiet=TRUE, tangle=TRUE); \ markdownToHTML('${mdfile}.md', '${mdfile}.html'); browseURL('${mdfile}.html')" else exit 0 fi