#!/bin/bash # Save any old workspace. if [ -e ".RData.xyztmp" ] then echo "A file named .RData.xyztmp already exists. Please remove this before proceeding." exit 1 fi if [ -e ".RData" ] then mv .RData .RData.xyztmp fi # Execute redefine-graphics-devices.R and save results in fresh workspace. # Don't want an outfile here. R CMD BATCH --no-restore --save redefine-graphics-devices.R /dev/null # Now run the R script passed in as $1, # which will have access to anything defined in our new workspace. # $2 is passed to the R script as an argument, # this will just be ignored unless you look for it, # but it gives you the option to pass args to your script. R CMD BATCH --restore --no-save "--args $2" $1 $1out rm .RData # Syntax highlight and create HTML file using Pygments pygmentize -o $1.html -O full $1out # Now look for png_filename: or jpg_filename: and convert to HTML img tags. RUBY_CMD="gsub(/(png|jpg)_filename:([0-9\.A-Za-z-]+\.(png|jpg))<\/span>/, '')" ruby -pe "$RUBY_CMD" < $1.html > $1-with-images.html # Restore any old workspace. if [ -e ".RData.xyztmp" ] then mv .RData.xyztmp .RData fi