|
#! /usr/local/bin/Rscript --vanilla |
|
|
|
##nemo_action_spin_html.r |
|
##2014-04-29 [email protected] |
|
##This script uses knitr::spin to process an R file. |
|
##Pandoc is may be used to obtain a PDF file. |
|
|
|
## I use hidden variables in this script (names start with dot) |
|
## so that rm in the compiled script does not clear them. |
|
|
|
## In spin |
|
## format = "Rmd" -> always creates the file .Rmd |
|
## knit = TRUE -> creates the file .md |
|
## report = TRUE -> creates the file .html |
|
|
|
## R.version.string ##"R version 3.0.2 (2013-09-25)" |
|
## packageDescription ("knitr", fields = "Version") #"1.5" |
|
|
|
library (tools) |
|
library (knitr) |
|
opts_chunk$set (echo = FALSE, comment = "", results = "hide") ## results = "markup" results = "hide" results = "asis" |
|
|
|
## input file |
|
.inFile = commandArgs (trailingOnly = TRUE)[1] |
|
.baFile <- file_path_sans_ext (.inFile) |
|
|
|
.mdFile <- paste0 (.baFile, ".md") |
|
.rmdFile <- paste0 (.baFile, ".Rmd") |
|
|
|
## wd for knitr; otherwhise it works at home |
|
setwd (dirname (.inFile)) |
|
|
|
|
|
## spin HTML |
|
.htmlFile <- paste0 (.baFile, ".html") |
|
unlink (.htmlFile) |
|
spin (.inFile, knit = TRUE, report = TRUE, format = "Rmd") ##html |
|
unlink (c (.rmdFile, .mdFile)) |
|
|
|
## ## spin PDF |
|
## .pdfFile <- paste0 (.baFile, ".pdf") |
|
## unlink (.pdfFile) |
|
## spin (.inFile, knit = TRUE, report = FALSE, format = "Rmd") ##just md |
|
## system (paste ("pandoc -V geometry:margin=25mm -o", .pdfFile, .mdFile)) |
|
## unlink (c (.rmdFile, .mdFile)) |
|
|
|
## exit |
|
q ("no") |