title: How do I change color of warning and error messages in knitr output chunk without losing wrapping?
body: <p>I would like the warnings and errors printed in the output chunk to be black rather than fuchsia and red, respectively.  I have attempted to follow the conversation here <a href="https://github.com/yihui/knitr/issues/264" rel="nofollow noreferrer">github.com/yihui/knitr/issues/264</a> to fix this problem.  Here is a short example of what I have so far (first chunk).</p>
  
  <pre><code>\documentclass{article}
  \begin{document}
  &lt;&lt;echo=FALSE&gt;&gt;=
  color_block = function(color) {
    function(x, options) sprintf('{\\color{%s}\\begin{verbatim}%s\\end{verbatim}}',color, x)
  }
  knit_hooks$set(warning=color_block('black'),error=color_block('black'))
  @
  
  &lt;&lt;&gt;&gt;=
  lens &lt;- c(10,20,30,40)
  lens + c(100,200,300)
  @
  \end{document}
  </code></pre>
  
  <p>I have succeeded in changing the colors of the messages to be black but the messages now do not wrap to stay within the output chunk boundaries and there are extra spaces before and after the message (see result of second chunk).</p>
  
  <p>From this <a href="https://stackoverflow.com/questions/28241686/how-can-knitr-keep-warning-messages-inside-the-box">SO discussion</a>, I thought that a <code>\raggedright</code> might help but I don't understand this code well enough to appropriately modify it.</p>
  
  <p>Any help would be appreciated.  Thank you in advance.</p>
  
  <p>p.s., this is a duplicate of my <a href="https://groups.google.com/forum/#!topic/knitr/HZpnq57ftoQ" rel="nofollow noreferrer">unanswered question on the knitr Google Group from a few days ago</a>.</p>