From 68c382dfb246a5b944ffd630bc3ad9066b559347 Mon Sep 17 00:00:00 2001 From: pascal Date: Wed, 1 Apr 2015 16:53:23 +0200 Subject: [PATCH 1/2] Rio: added option '-p' to give PDF output --- tools/Rio | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/Rio b/tools/Rio index badf4bd5..48295735 100755 --- a/tools/Rio +++ b/tools/Rio @@ -1,5 +1,5 @@ #!/bin/bash -# Rio: Load CSV from stdin into R as a data.frame, execute given commands, and get the output as CSV or PNG on stdout +# Rio: Load CSV from stdin into R as a data.frame, execute given commands, and get the output as CSV, PNG or PDF on stdout # # Example usage: # $ < seq 100 | Rio -nf sum (same as Rio -ne 'sum(df)') @@ -30,6 +30,7 @@ OPTIONS: -r Import dplyr and tidyr -s Import sqldf -b Use same settings as used for book Data Science at the Command Line + -p Export graphic as PDF -v Verbose EOF @@ -57,6 +58,7 @@ REQUIRES= DELIMITER="," HEADER="T" VERBOSE=false +PDF=false # OSX `mktemp' requires a temp file template, but Linux `mktemp' has it as optional. # This explicitly uses a template, which works for both. The $TMPDIR is in case @@ -68,7 +70,7 @@ IN=$(mktemp ${TMPDIR}/Rio-XXXXXXXX) OUT=$(mktemp ${TMPDIR}/Rio-XXXXXXXX).png ERR=$(mktemp ${TMPDIR}/Rio-XXXXXXXX).err -while getopts "d:hgnprsve:f:b" OPTION +while getopts "d:hgnprspve:f:b" OPTION do case $OPTION in b) @@ -106,6 +108,9 @@ do v) VERBOSE=true ;; + p) + PDF=true + ;; ?) usage exit @@ -115,6 +120,11 @@ done cat /dev/stdin > $IN +if $PDF +then + OUT=$(mktemp ${TMPDIR}/Rio-XXXXXXXX).pdf +fi + if $VERBOSE then callR From 2e583521cefcc2e0a27348dd00dd243a02de2bc0 Mon Sep 17 00:00:00 2001 From: pascal Date: Thu, 2 Apr 2015 08:24:53 +0200 Subject: [PATCH 2/2] Rio pdf: code cleanup and deleting pdf temp file --- tools/Rio | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/Rio b/tools/Rio index 48295735..96dad0fe 100755 --- a/tools/Rio +++ b/tools/Rio @@ -37,7 +37,7 @@ EOF } finish() { - rm -f $IN $OUT ${OUT%.png} ${ERR%.err} + rm -f $IN $OUT ${OUT%.png} ${OUT%.pdf} ${ERR%.err} ## Removes error file if error file is empty. if [[ ! -s $ERR ]]; then @@ -58,7 +58,6 @@ REQUIRES= DELIMITER="," HEADER="T" VERBOSE=false -PDF=false # OSX `mktemp' requires a temp file template, but Linux `mktemp' has it as optional. # This explicitly uses a template, which works for both. The $TMPDIR is in case @@ -109,7 +108,7 @@ do VERBOSE=true ;; p) - PDF=true + OUT=${OUT%.png}.pdf ;; ?) usage @@ -120,11 +119,6 @@ done cat /dev/stdin > $IN -if $PDF -then - OUT=$(mktemp ${TMPDIR}/Rio-XXXXXXXX).pdf -fi - if $VERBOSE then callR