forked from AberdeenStudyGroup/studyGroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
knitpost.R
30 lines (26 loc) · 759 Bytes
/
knitpost.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/Rscript --vanilla
#
# Convert a Rmd file to a md file for Jekyll
#
# Usage:
# -arg1 The Rmd file to convert to md for Jekyll use.
#
# Example:
# cd lesson/lesson_name/
# Rscript ../../knitpost.R lesson.Rmd
#
# Change `visible: false` to `visible: true` in the generated lesson.md file.
#
KnitPost <- function(input) {
outfile <- rename_to_post(input)
knitr::opts_knit$set(base.url = '../')
knitr::opts_chunk$set(fig.cap = "center")
knitr::render_markdown()
knitr::knit(input, outfile, envir = parent.frame())
}
rename_to_post <- function(draft)
paste0(sub(".Rmd$", ".md", draft))
args <- commandArgs(trailingOnly = TRUE)
if (length(args) > 1)
stop('Please pass only one argument: the file.')
KnitPost(args[1])