title: Determine ghostscript version
body: <p>I once did a blog on combining graphis with external programs and received a terrific comment from a reader (<a href="http://trinkerrstuff.wordpress.com/2012/10/08/splitting-and-combining-r-pdf-visuals/#comment-133" rel="nofollow">-click here-</a>) on implementing this entirely within R with ghostscript as seen below.  I have been using this a bit lately and am wanting to share it with others.  I'd like to modify it to make the function more intuitive and detecting the ghostscript type is one mod I'd like to do but can't.  The unix vs. windows is easy via <code>.Platform</code>.  The sticking point is the windows 32 vs. 64 that I struggle with.  </p>
  
  <p>How can I use R to detect which ghostscript version (gswin32c or gswin64c) is running?  Merely looking at the computer's specifications isn't good enough because I run gswin32c on a Win 64 machine.  The idea is to remove the os argument entirely or set it to <code>NULL</code> and have the function try to access this information.</p>
  
  <pre><code>mergePDF &lt;- function(infiles, outfile, os = "UNIX") {
      version &lt;- switch(os,
          UNIX = "gs",
          Win32 = "gswin32c",
          Win64 = "gswin64c")
      pre = " -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="
      system(paste(paste(version, pre, outfile, sep = ""), infiles, collapse = " "))
  }
  
  
  pdf("file1.pdf", width = 10, height = 8)
  plot(1:10, col="red", pch = 19)
  dev.off()
  
  pdf("file2.pdf", width = 16, height = 8)
  plot(1:10)
  dev.off()
  
  mergePDF("file1.pdf file2.pdf", "mergefromR.pdf", "Win32")
  </code></pre>