Here are the examples of the r api knitr-pat_md taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
File: utils-rmd.R, author: datacamp, license: GNU Affero General Public License v3.0
build_doc_structure < - function(text) {
old.format < - knitr::opts_knit$get()
knitr::opts_knit$set(out.format = "markdown")
apat < - knitr::all_patterns
opat < - knitr::knit_patterns$get()
on.exit({
knitr::knit_patterns$restore(opat)
knitr:::chunk_counter(reset = TRUE)
knitr:::knit_code$restore(list())
knitr::opts_knit$set(old.format)
})
knitr::pat_md()
content = knitr:::split_file(lines = knitr:::split_lines(text))
code_chunks < - knitr:::knit_code$get()
for (i in seq_along(content)) {
if (class(content[[i]]) == "block") {
label < - content[[i]]$params$label
content[[i]]$input < - paste(code_chunks[[label]],
collapse = "\n")
}
}
content[sapply(content, function(part) {
all(grepl(pattern = "^\\s*$", x = part$input.src)) &&
class(part) == "inline"
})] < - NULL
return(content)
}