Two changes: 1: Use triple-backslash-n in the cat call in callR function.  Original formulation, with one-backslash-n in the call was causing an error, because I believe that bash was interpolating this to an actual newline in the code, not the backslash-n sequence to pass to Rscript.  Should be tested on Linux, but works on Mac.  2: Creation of temp files left two empty files, one with name of OUT but without the .png suffix, and one with the name of ERR but without the .err suffix.  Added call in trap call to clean up those files, as I cannot figure out a portable way to just create single temp files with .png and .err suffix, as the --suffix arg to mktemp is not universal.