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

started rendr

parent 4696ef5b
No related branches found
No related tags found
No related merge requests found
rend.R - A shell-wrapper for rmarkdown::render
===
Installation
---
Download a local copy and add it to your path using
```
targetDirectory=~/bin
wget -P $targetDirectory --no-check-certificate https://raw.githubusercontent.com/holgerbrandl/datautils/master/R/rendr/rend.R
chmod +x $targetDirectory/rend.R
export PATH=$targetDirectory:$PATH
```
Usage
---
To use it from a shell you can call rend.R directly with a script as argument.
```
rend.R MyScript.R
```
or for Rmd
```
rend.R MyScript.Rmd
```
The report will be created in the current working directory. To learn about options just call `rend.R --help`
In case you want to render R snippets you can source a small bash function that wraps rend.R
```
source <(curl https://raw.githubusercontent.com/holgerbrandl/datautils/master/R/rendr/rendr_utils.sh 2>&1 2>/dev/null)
```
Now you can spin R snippets by piping them into `spinsnip`
```
echo "require(ggplot2); ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point()" | rendr_snippet "my_report"
```
File moved
rendr(){
## test if present in PATH
if [ -z "$(which rendr.R)" ]; then
>&2 echo "rendr.R is not installed. See https://github.com/holgerbrandl/datautils/tree/master/R/rendr for details"
fi
spin.R $*
}
export -f spinr
rendr_snippet(){
if [ $# -lt 1 ]; then
>&2 echo "Usage: rendr_snippet <report name> [other args]*"
>&2 echo "The R snippet to be spinned will be read from standard input."
return
fi
reportName=$1
tmpR=$(mktemp -d)/$(echo $reportName | tr " " "_").R
## http://stackoverflow.com/questions/11454343/pipe-output-to-bash-function
cat | sed 's/#>/#'"'"'/g' > $tmpR
echo "rendering $tmpR..."
shift
rendr -e $tmpR $*
# rm -r $(dirname $tmpR)
rm ${tmpR}
}
export -f spinsnip
## usage example
# echo '
# > # test report
# 1+1;
# ggplot(iris, aes(Sepal.Width) + geom_histogram()
# ' | spinsnip some_report
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