title: How do I get capture.output functionality while capturing ANSI color codes from crayon?
body: <p>What ways are there to capture output <em>à la</em> <code>capture.output</code> but which will retain the ANSI color encoding which comes out of <code>crayon</code>?</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; crayon::green("green")
  [1] "\033[32mgreen\033[39m"
  &gt; capture.output(crayon::green("green"))
  [1] "[1] \"green\""
  </code></pre>
  
  <p>Edit:  Another example </p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; green &lt;- function() {
  +   print(crayon::green("green"))
  +   cat(crayon::green("green"))
  +   
  +   invisible()
  + }
  &gt; green()
  [1] "\033[32mgreen\033[39m"
  green
  &gt; capture.output(green())
  [1] "[1] \"green\"" "green"        
  &gt; 
  </code></pre>