-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathextract-README-examples.R
32 lines (28 loc) · 1.22 KB
/
extract-README-examples.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extractCodeBlocks <- function(sourceFile, afterLines, targetFile) {
text <- readLines(sourceFile)
code <- unlist(lapply(afterLines, function(markLine) {
markIdx <- match(markLine, text)
codeBlockStart <- Find(function(i) {startsWith(text[i], "```")},
(markIdx + 1):length(text))
codeBlockEnd <- Find(function(i) {startsWith(text[i], "```")},
(codeBlockStart + 1):length(text))
code <- text[(codeBlockStart + 1):(codeBlockEnd - 1)]
code[length(code)+1] <- ""
code
}))
writeLines(code, targetFile)
}
extractIrisExample <- function() {
extractCodeBlocks("README.md", c("<!-- Julia-iris-data -->",
"<!-- Julia-iris-training -->"),
"inst/examples/iris-example/iris-example.jl")
extractCodeBlocks("README.md", c("<!-- R-iris-data -->",
"<!-- R-iris-training -->"),
"inst/examples/iris-example/iris-example.R")
}
extractBoltzmannExample <- function() {
extractCodeBlocks("README.md", "<!-- Boltzmann-Example -->",
"inst/examples/boltzmann-example.R")
}
extractIrisExample()
extractBoltzmannExample()