【发布时间】:2015-10-07 17:50:48
【问题描述】:
我正在尝试使用 R 中的 knitr 和 pander 包创建带有表格的 pdf,但似乎我表格中的某些文本被误解为代码,因为生成的文档显示了文本在不应该的时候逐字逐句。这是一些示例代码,我可以在其中复制问题。
---
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)
```
我尝试使用pander_return 而不是pander 函数,然后使用Pandoc.convert 将该文本转换为LaTeX,这样我就可以用任何内容替换所有\begin{verbatim} 和\end{verbatim},但这不起作用。现在这是有道理的,因为我试图在我的 Rmd 文件中这样做。
就在发布此问题之前,我确实注意到,如果我从 test_name 列中删除所有 /,则该列不再存在逐字记录问题,但问题仍然存在于campaigns 和 results 列。
如何让它识别出文本是降价代码而不是逐字代码?非常感谢任何帮助。
编辑:一旦我从第一列中删除“特殊字符”,它似乎只会将单元格文本视为单元格中的单个单词时的逐字代码。否则看起来很好。
【问题讨论】:
-
添加
justify = 'left' -
你为什么要这样使用
return? -
justify = 'left'工作。我正在使用pander_return将文本从 pander 输出到 R 对象。但我意识到使用Pandoc.convert在我的文档中创建了一个全新的文档,导致了 LaTeX 问题。 -
哦,那个
return。我不太确定return在做什么......我习惯于将它放在我的shiny和其他网络应用程序中,作为一种“舒适”,我猜,希望它确保正确的对象是转换为markdown或传递给ui。 :) -
第二个 @rawr 使用左对齐 --
pander默认为center。如果您不喜欢这样,您可以使用panderOptions全局更新该设置。关于return:无需指定pander返回的内容并调用return,因为它不返回任何内容,而是写入stdout。好吧,在后台它有点复杂,但为了简短起见:works fine inknitr。
标签: r knitr r-markdown pander