I am working on a document in R, with knitr for pdflatex and using the extended version of toLatex from memisc.
When I create a table with cut intervals, the square brackets are not sanitized, and pdflatex job errors due to the existence of [ .
I tried putting sanitize=TRUE in chitr code, but this only works for tikz.
I used to use gsub and replaced the string in the R object itself, which is rather inelegant. I hope someone can point me in the direction of the nuance of memisc or knitr, which I do not have, or another function / method that can easily cope with special latex characters.
Example
library("memisc") library("Hmisc") example<-data.frame(cbind(x=1:100,y=1:100)) example$x<-cut2(example$x,m=20) toLatex(example)
UPDATE
SO Search I found a post about using latexTranslate with the apply function, but this requires characters, so I would need to separate from factor to character.
I found another SO post that identifies the knitr:::escape_latex , however the piece then outputs the material as markup instead of translating (using results = 'asis') or creating an R-style table inside the code block (using results =' markup). I tried to configure it as a hook function in my parent document, and this led to the output of the entire contents of the document as markup. This is a completely new area for me, so I probably implemented it incorrectly.
<<setup,include=FALSE>>= hook_inline = knit_hooks$get('inline') knit_hooks$set(inline = function(x) { if (is.character(x)) x = knitr:::escape_latex(x) hook_inline(x) }) @ ... <<tab-example,echo=FALSE,cache=TRUE,results='asis',sanitize=TRUE,inline=TRUE>>= library("Hmisc") library("memisc") example<-data.frame(cbind(x=1:100,y=1:100)) example$x<-cut2(example$x,m=20) toLatex(example) @
According to @yihui, this is the wrong way
UPDATE 2
I created a gsub shell that will exit percentages, etc., however [the symbol still pushes latex into math and error mode.