title: How to output to pdf using knitr/xtable when tex has square braces ( [ )?
body: <p>I am trying to output the freq table generated by <code>cut</code> to a PDF file using knitr and xtable. However, when I include the option <code>include.rownames=FALSE</code> the output is not processed and an error is reported whereas the code works with <code>include.rownames=TRUE</code>. Test code is below:</p>
  
  <pre><code>\documentclass[12pt]{article}
  
  \begin{document}
  
  &lt;&lt;test_table, results = "asis",echo=FALSE&gt;&gt;=
  library(xtable)
  x &lt;- sample(10,100,replace=TRUE)
  breaks &lt;- c(1,2,5,10)
  x.freq &lt;- data.frame(table(cut(x, breaks, right=FALSE)))
  print(xtable(x.freq),include.rownames=TRUE)
  @
  
  \end{document}
  </code></pre>
  
  <p>When I use <code>include.rownames=TRUE</code> I get the output below.</p>
  
  <blockquote>
    <p>1 [1,2) 5<br>
    2 [2,5) 35<br>
    3 [5,10) 49</p>
  </blockquote>
  
  <p>whereas when I use <code>include.rownames=FALSE</code> I get an error:</p>
  
  <blockquote>
    <p>Test.tex:71: LaTeX Error: \begin{tabular} on input line 58 ended by \end{document}.</p>
  </blockquote>
  
  <p>I believe that I am getting the error because of the presence of the square braces ' [ ' in the text source. </p>
  
  <p>Does anyone know how to solve this problem?</p>