diff --git a/R/rendr/README.md b/R/rendr/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3b8ce047aa8cd32be1d1f4efc9b871c5a817fc68 --- /dev/null +++ b/R/rendr/README.md @@ -0,0 +1,43 @@ +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" +``` + + + + diff --git a/R/spinr/rende.R b/R/rendr/rend.R similarity index 100% rename from R/spinr/rende.R rename to R/rendr/rend.R diff --git a/R/rendr/rendr_utils.sh b/R/rendr/rendr_utils.sh new file mode 100755 index 0000000000000000000000000000000000000000..4f0979f7cb680dba968fbaa0b32ebde28594f6a9 --- /dev/null +++ b/R/rendr/rendr_utils.sh @@ -0,0 +1,41 @@ + +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