(.. .Rprofile, - YAML):
- yaml pandoc ! d'!
knit: , , , Ctrl + Shift + K.
1: YAML .
YAML
common.yaml:
---
author: me
date: "'r format (Sys.time(), format='%Y-%m-%d %H:%M:%S %z')'"
link-citations: true
reference-section-title: References
---
, , .. --- .
YAML pandoc, YAML (. github)
. example.rmd:
title: On the Culinary Preferences of Anthropomorphic Cats
output:
html_document:
pandoc_args: './common.yaml'
I do not like green eggs and ham. I do not like them, Sam I Am!
html_document: _output.yaml, rmarkdown output: . , YAML , .
:
:
- YAML
knit, . "r format (Sys.time(), format = '% Y-% m-% d% H:% M:% S% z')". github:
, .
, - .
2: knit
, /.
rmarkdown: knit: YAML , "Knit" Rstudio.
:
myknit(inputFile, encoding), YAML, RMD render . myknit.r.YAML example.rmd
knit: (function (...) { source('myknit.r'); myknit(...) })
, . source('myknit.r') , YAML, . myknit.r, YAML. , YAML, , knit; YAML common.yaml.
Ctrl + Shift + K , , Rstudio.
:
myknit make, make .- YAML
rmarkdown , , , render. : myknit () Output created: path/to/file.html, .
, [ ], . , render ( "Output output: basename.extension"), , render(..., quiet=T), suppressMessages(render(...)) ( knitr progress pandoc output) .
:
:
- , 1
knit: ( source('./myknit.r'), , )
. myknit.r common.yaml. .Rprofile .
example.rmd:
---
title: On the Culinary Preferences of Anthropomorphic Cats
knit: (function (...) { source('myknit.r'); myknit(...) })
---
I do not like green eggs and ham. I do not like them, Sam I Am!
common.yaml []:
author: me
date: "'r format (Sys.time(), format='%Y-%m-%d %H:%M:%S %z')'"
link-citations: true
reference-section-title: References
myknit.r:
myknit <- function (inputFile, encoding, yaml='common.yaml') {
yaml <- readLines(yaml)
rmd <- readLines(inputFile)
yamlHeader <- grep('^---$', rmd)[1]
rmd <- append(rmd, yaml, after=yamlHeader)
ofile <- file.path(tempdir(), basename(inputFile))
writeLines(rmd, ofile)
message(ofile)
ofile <- rmarkdown::render(ofile, encoding=encoding, envir=new.env())
file.copy(ofile, file.path(dirname(inputFile), basename(ofile)), overwrite=T)
}
Ctrl + Shift + K/Knit example.rmd . , common.yaml, , example.rmd .