【问题标题】:knitr treats markdown text as verbatimknitr 将 Markdown 文本逐字处理
【发布时间】:2015-10-07 17:50:48
【问题描述】:

我正在尝试使用 R 中的 knitrpander 包创建带有表格的 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 列中删除所有 /,则该列不再存在逐字记录问题,但问题仍然存在于campaignsresults 列。

如何让它识别出文本是降价代码而不是逐字代码?非常感谢任何帮助。

编辑:一旦我从第一列中删除“特殊字符”,它似乎只会将单元格文本视为单元格中的单个单词时的逐字代码。否则看起来很好。

【问题讨论】:

  • 添加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 in knitr

标签: r knitr r-markdown pander


【解决方案1】:

根据@rawr 的评论,将justify= 'left' 添加到pander 函数解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 2013-08-05
    • 2017-07-28
    • 2020-10-23
    相关资源
    最近更新 更多