Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Added R script to create html content for the full R intermediate boo…
Browse files Browse the repository at this point in the history
…tcamp.
  • Loading branch information
jdblischak committed Feb 20, 2014
1 parent 5787ec4 commit 4bacbe7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions intermediate/r/knit_intermediate_bootcamp.R
@@ -0,0 +1,34 @@
#!/usr/bin/Rscript

# Knits all the files for the SWC intermediate R bootcamp

# Should be executed from within the directory: bc/intermediate/r

library(markdown)
library(knitr)

cwd <- normalizePath(getwd())
dirs <- strsplit(cwd, "/")[[1]]
if (dirs[length(dirs)] != "r") {
stop("This script needs to be run from within bc/intermediate/r.")
}

# Knit Rmd files to html, remove intermediate md files
files <- list.files(pattern = "Rmd$", recursive = TRUE, full.name = TRUE)
files <- normalizePath(files)
for (fname in files) {
setwd(dirname(fname))
knit2html(input = basename(fname), envir = new.env())
unlink(sub(".Rmd$", ".md", basename(fname)))
}

# Convert md files to html
setwd(cwd)
files <- list.files(pattern = "\\.md$", recursive = TRUE, full.name = TRUE)
files <- normalizePath(files)
for (fname in files) {
if (basename(fname) == "README.md") {
next
}
renderMarkdown(file = fname, output = sub("md$", "html", fname))
}

0 comments on commit 4bacbe7

Please sign in to comment.