Skip to content
Snippets Groups Projects
Commit 8bf62023 authored by Holger Brandl's avatar Holger Brandl
Browse files

cont. rknit

parent b97ecec7
No related branches found
No related tags found
No related merge requests found
......@@ -4,32 +4,29 @@
rknit(){
## rscript=/projects/project-raphael/Rcode/misc/DivisionPerpendicularity.R
## rscript=/home/brandl/mnt/mack/project-raphael/Rcode/misc/DivisionPerpendicularity.R
## rscript=/Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_example.R
rscript=$1
# tmdRmd=$(mktemp --suff .Rmd)
tmdRmd=$(basename $rscript .R).Rmd
echo '# '$(basename $rscript .R) > $tmdRmd
# echo '# '$(basename $rscript .R) > $tmdRmd
## alternatively we could use the header argument for knit2html
echo '
<style type="text/css">
body {
max-width: 80%;
}
body {
max-width: 80%;
}
</style>
```{r}
' >> $tmdRmd
cat $rscript | grep -Fv "#!" | Rscript -e 'require(stringr); require(dplyr); readLines(file("stdin")) %>% str_replace("##> ([^{]*)[{](.*)[}]", "```\n\\1\n```{r \\2}") %>% writeLines(stdout()) ' >> $tmdRmd
' > $tmdRmd
# cat $rscript | grep -Fv '#!' | Rscript --vanilla - 'require(stringr); require(dplyr); readLines(file("stdin")) %>% str_replace("^#([#]*)> ([^{]*)([{]+.+[}])?", "```\n\\1 \\2\n```{r \\3}") %>% collapsewriteLines(stdout())' # >> $tmdRmd
cat $rscript | grep -Fv '#!' | Rscript --vanilla -e 'source("/Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_preprocessor.R")' >> $tmdRmd
echo '```' >> $tmdRmd
echo 'require(knitr); options(width=150); opts_knit$set(cache = TRUE); knit2html("'$tmdRmd'", output="'$(basename $rscript .R)'")' | R --vanilla -q
}
echo '
##> # Prepare elongation data
' | Rscript -e 'require(stringr); require(dplyr); readLines(file("stdin")) %>% str_replace("##> ([^{]*)[{](.*)[}]", "```\n\\1\n```{r \\2}") %>% writeLines(stdout()) '
#> {message=F, echo=F}
require(dplyr)
require(gplot)
require(ggplot2)
##> test
###> test heading
#> ... followed by some markup
head(iris)
#> some markup
ggplot(iris, aes(Species, Sepal.Length, fill=Species)) + geom_boxplot() + scale_fill_discrete(guide=F)
#> {fig.width=14}
## just chunk definition without markdown text or header
ggplot(iris, aes(Species, Sepal.Length, fill=Species)) + geom_boxplot() + scale_fill_discrete(guide=F)
# source /Users/brandl/Dropbox/Public/datautils/R/rknit/rknit.sh ; rknit /Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_example.R
\ No newline at end of file
# source /Users/brandl/Dropbox/Public/datautils/R/rknit/rknit.sh ;
# rknit /Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_example.R
require(stringr);
require(dplyr);
#readLines(file("stdin")) %>%
mdRegex <- "^#([#]*)> ([^{]*)([{]+(.+)[}])?"
#str_match("##> test heading", mdRegex)
#str_match("##> test heading {fig.width=10}", mdRegex)
#str_match("#> simple markup", mdRegex)
#str_match("#> {fig.width=10}", mdRegex)
readLines(file("/Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_example.R")) %>%
str_replace(mdRegex, "```\n\\1 \\2\n```{r \\4}") %>% paste(collapse="\n") %>% cat(stdout())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment