1

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 instead of the 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.

enter image description here

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.

enter image description here

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.

Mark Nielsen
  • 991
  • 2
  • 10
  • 28
  • 2
    add `justify = 'left'` – rawr Oct 07 '15 at 18:31
  • why are you using `return` like that? – rawr Oct 07 '15 at 18:32
  • `justify = 'left'` worked. I was using `pander_return` to output the text from pander to an R object. But I realized using `Pandoc.convert` created an entirely new document within my document, causing LaTeX issues. – Mark Nielsen Oct 07 '15 at 18:40
  • Oh, that `return`. I'm not quite sure what `return` is doing... I'm used to putting it there for my `shiny` and other web apps as sort of a "comfort" I guess, hoping that it ensures the right object is converted to markdown or passed to the ui. :) – Mark Nielsen Oct 07 '15 at 18:46
  • Seconding @rawr with using left alignment -- `pander` defaults to `center`. If you do not like that, you can use `panderOptions` to update that setting globally. About `return`: no need to assign what's returned by `pander` and calling `return` it, as it does not return anything but writes to the `stdout`. Well, in the background it's a bit more complex, but to keep it short: [works fine in `knitr`](http://blog.rapporter.net/2014/09/pander-tables-inside-of-knitr.html). – daroczig Oct 07 '15 at 19:26

1 Answers1

0

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

Mark Nielsen
  • 991
  • 2
  • 10
  • 28