From 6e60b9ef07e4bc4ad6330de39e6cecd69eb22c6d Mon Sep 17 00:00:00 2001 From: Holger Brandl <brandl@mpi-cbg.de> Date: Thu, 18 Sep 2014 12:54:34 +0200 Subject: [PATCH] started spinr wrapper --- R/utils/spinr.R | 42 ++++++++++++++++++++++++++++++++++++++++++ R/utils/spinr.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 R/utils/spinr.R create mode 100644 R/utils/spinr.sh diff --git a/R/utils/spinr.R b/R/utils/spinr.R new file mode 100644 index 0000000..d61a394 --- /dev/null +++ b/R/utils/spinr.R @@ -0,0 +1,42 @@ +## a thin wrapper around spin to make it more useful with more custom output +require(knitr) +require(stringr) + +options(width=150) + +#https://groups.google.com/forum/#!topic/knitr/ojcnq5Nm298 + +## better table css: http://www.stat.ubc.ca/~jenny/STAT545A/topic10_tablesCSS.html + +#setwd("/local/home/brandl/mnt/mack/project-raphael/reports/spin_report") +#setwd("/home/brandl/mnt/mack/project-raphael/reports/spin_report") + +#rScript='/home/brandl/mnt/mack/project-raphael/Rcode/misc/DivisionPerpendicularity.R' +#rScript='/home/brandl/mnt/mack/project-raphael/Rcode/misc/Test.R' + +#spinr <- function(rScript){ + print(Sys.getenv("TISSMORH_SCRIPTS")) + spin(rScript, knit=F) + + mdScript <- str_replace(rScript, "[.]R$", ".Rmd") + + system(paste("mv", mdScript, "tmp.Rmd")) + system(paste("cat tmp.Rmd | grep -Ev '^#+$' | grep -Fv '#!/usr/bin/env Rscript' >", basename(mdScript))) + + cssHeader=' + <style type="text/css"> + body { + max-width: 90%; + } + </style> + ' + ls() + + opts_chunk$set(cache = TRUE, fig.width=10, width=120) + knit2html(basename(mdScript)) + + #file.remove(mdScript) +#} + +# spinr("/home/brandl/mnt/mack/project-raphael/Rcode/misc/DivisionPerpendicularity.R") +# spinr("/home/brandl/mnt/mack/project-raphael/Rcode/misc/Test.R") diff --git a/R/utils/spinr.sh b/R/utils/spinr.sh new file mode 100644 index 0000000..34d78dc --- /dev/null +++ b/R/utils/spinr.sh @@ -0,0 +1,26 @@ + + +spinr(){ + if [ $# -ne 1 ]; then + echo -e "Usage: spinr <script.R>\nJust knit R documents as they are, no markdown is required (but supported to some extent)" + return + fi + + rscript=$1 + + if [ ! -f $rscript ]; then + >&2 echo "$rscript does not exist"; exit; + fi + + ## rscript=/Users/brandl/Dropbox/Public/datautils/R/rknit/rknit_example.R + +# echo 'devtools::source_url("https://dl.dropboxusercontent.com/u/113630701/datautils/R/utils/spinr.R"); spinr("'$rscript'")' | R --vanilla -q + echo 'rScript="'$rscript'"; devtools::source_url("https://dl.dropboxusercontent.com/u/113630701/datautils/R/utils/spinr.R")' | R --vanilla -q +} + + +#' cd /home/brandl/mnt/mack/project-raphael/reports/spin_report +#' source <(curl https://dl.dropboxusercontent.com/u/113630701/datautils/R/utils/spinr.sh) +#' spinr /home/brandl/mnt/mack/project-raphael/Rcode/misc/DivisionPerpendicularity.R +#' spinr /home/brandl/mnt/mack/project-raphael/Rcode/misc/Test.R + -- GitLab