Skip to content

Instantly share code, notes, and snippets.

@jwdink
Created December 21, 2015 17:33
Show Gist options
  • Save jwdink/2e1853e0dff254c131ac to your computer and use it in GitHub Desktop.
Save jwdink/2e1853e0dff254c131ac to your computer and use it in GitHub Desktop.
Take an .Rmd file and Generate a more generic .markdown file
generate_markdown_for_site <- function(path_to_rmd, path_to_knit_to) {
filename <- basename(path_to_rmd)
message("Setting working directory to ", path_to_rmd)
setwd(dirname(path_to_rmd))
post_name <- sub("^([^.]*).*", "\\1", filename)
content <- readLines(paste0(post_name, ".Rmd"))
render_markdown(strict=TRUE)
opts_knit$set(out.format='markdown')
opts_knit$set(base.dir= paste0(path_to_knit_to, "/", post_name,"/") )
opts_knit$set(base.url= paste0("/static/",post_name,"/") )
opts_chunk$set(fig.height = 4, fig.width = 7, dpi = 96)
knit(text=content, output= paste0(path_to_knit_to, "/", post_name, ".markdown"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment