Mark Nielsen - 1 year ago 85
R Question

# knitr treats markdown text as verbatim

I'm trying to create a pdf with a table using

knitr
and
pander
packages in R, but it appears that some of the text in my table is being misinterpreted as code, because the resulting document shows the text as verbatim when it shouldn't. Here is some sample code where I have been able to replicate the issue.

---
title: "Untitled"
author: "Me"
date: "10/07/2015"
output: pdf_document
classoption: landscape
---

\footnotesize
{r,echo=F,message=F}
library(pander)
dat <- data.frame(test_name=c("Short","Really, really long test name","Other","The rest/Other/whatever"),
campaigns=c("AAA BBB CCC","AAA","BBB CCC","DDD"),
objective=c("We want to test whether or not the changes we made to our proceedure will change the outcome. We will test this from January 2015 to January 2016.","I am not very creative and cannot think of any other objectives especially since I made up the rest of this stuff.","Our objective is to improve the quality of our product.","The objective is to find out if people will like this other product better."),
results=c("The test we did resulted in the following results that were counter-intuitive since we expected other results.","None","This other test resulted in everything as we expected, blah, blah, blah.","None"))

myTable <- pander(dat,split.cells=c(20,10,60,60),split.table=Inf,style='grid',emphasize.strong.cols=c(1))
return(myTable)



I tried using
pander_return
pander
function and then convert that text to LaTeX using
Pandoc.convert
so I could replace all the
\begin{verbatim}
and
\end{verbatim}
with nothing, but that didn't work. Which makes sense now since I tried to do that within my Rmd file.

Just before posting this question, I did notice that if I remove all
/
's from the
test_name
column, I don't have a verbatim issue any longer for that column, but the problem still exists in the
campaigns
and
results
columns.

How do I get it to recognize that the text is markdown and not verbatim code? Any help is much appreciated.

EDIT: Once I remove the "special characters" from the first column, it appears that it only treats the cell text as verbatim code when it is a single word in a cell. Otherwise it looks fine.

Based on the comment by @rawr, adding justify= 'left' to the pander function fixed the problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download