title: R to clipboard won't work on a mac
body: <p>I have wrapped the <code>strwrap</code> function into <code>strWrap</code> that accepts text from the clipboard as well as automatically writing to the clipboard.  In this I am assuming the system name for the mac is Darwin.  This function works on a windows machine (sorry Linux has too much variation to make it feasible &amp; most people that would use the package this function is for would not be linux users anyway).</p>
  
  <p>I modeled my function after the <code>psych</code> packages's <a href="http://personality-project.org/r/html/read.clipboard.html" rel="nofollow noreferrer">read.clipboard</a> function.  Unfortunately, I asked some people to try it out at <a href="http://www.talkstats.com/showthread.php/27194-test-and-improve-a-function-that-s-OS-independant" rel="nofollow noreferrer">talkstats.com</a> who had a mac and it doesn't work.  How can I make this work for mac as well?  According to <a href="https://stackoverflow.com/questions/9035674/r-function-to-copy-to-clipboard-on-mac-osx">this SO post</a> my code seems like it should work for mac users as well.</p>
  
  <p>If this works as expected it should be able to both read from the clipboard for mac users and write to the clipboard when finished.  I have marked the mac specific lines with a <code>#</code> at the end for easier understanding of the problem</p>
  
  <pre><code>strWrap &lt;-
  function(text = "clipboard", width = 70) {
      if (text == "clipboard") {
          if (Sys.info()["sysname"] == "Darwin") {        #
              text &lt;- paste(pipe("pbpaste"), collapse=" ")#
          }                                               #
          if (Sys.info()["sysname"] == "Windows") {
              text &lt;- paste(readClipboard(), collapse=" ")
          }
      } 
      x &lt;- gsub("\\s+", " ", gsub("\n|\t", " ", text))
      x &lt;- strwrap(x, width = width)
      if (Sys.info()["sysname"] == "Windows") {
          writeClipboard(x, format = 1)
      }
      if (Sys.info()["sysname"] == "Darwin") {           #
          j &lt;- pipe("pbcopy", "w")                       #
          cat(x, file = j)                               #
          close(j)                                       # 
      }                                                  #
      writeLines(x)
  }
  
  X &lt;- "Two households, both alike in dignity, In fair Verona, where we lay
  our scene, From ancient grudge break to new mutiny, Where civil blood
  makes civil hands unclean. From forth the fatal loins of these two
  foes A pair of star-cross'd lovers take their life; Whose
  misadventured piteous overthrows Do with their death bury their
  parents' strife. The fearful passage of their death-mark'd love, And
  the continuance of their parents' rage, Which, but their children's
  end, nought could remove, Is now the two hours' traffic of our stage;
  The which if you with patient ears attend"
  
  strWrap(X, 70)
  </code></pre>