Created
March 17, 2016 04:08
-
-
Save nhoffman/ddfe7f2cf90f4e85d1c2 to your computer and use it in GitHub Desktop.
knit R markdown files
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 characters
#!/usr/bin/env Rscript | |
if(Sys.getenv("VIRTUAL_ENV") == ""){ stop("An active virtualenv is required") } | |
source(file.path(Sys.getenv('VIRTUAL_ENV'), 'bin', 'rvenv')) | |
suppressPackageStartupMessages(library(argparse, quietly = TRUE)) | |
suppressPackageStartupMessages(library(rmarkdown, quietly = TRUE)) | |
main <- function(arguments){ | |
parser <- ArgumentParser() | |
parser$add_argument('infile') | |
parser$add_argument('-o', '--outfile') | |
parser$add_argument('-f', '--format', choices=c('html', 'pdf', 'all'), | |
default='html', help='output format [default %(default)s]') | |
args <- parser$parse_args(arguments) | |
format <- if(args$format == 'all'){ | |
'all' | |
}else{ | |
gettextf('%s_document', args$format) | |
} | |
rmarkdown::render( | |
args$infile, | |
output_file=args$outfile, | |
output_format=format) | |
} | |
main(commandArgs(trailingOnly=TRUE)) | |
## invisible(warnings()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment