Knitr没有在R代码块中包装行

时间:2015-04-24 09:55:19

标签: r knitr

我的knitr报告中的R代码块有问题,它们几乎没有用R代码在我的所有块中包装行。

enter image description here

这是一个典型的Rmd文件,其中包含以下块:

```{r}
batch_merged <- sqldf(c("update batch_merged set winning = 'mix' where (Homophily_Count BETWEEN 1 AND Agents_Count - 1) or (Heterophily_Count BETWEEN 1 AND Agents_Count - 1) or (Preferential_Count BETWEEN 1 AND Agents_Count - 1)", "select * from batch_merged"))
batch_merged <- sqldf(c("update batch_merged set winning = 'hom' where Homophily_Count = Agents_Count", "select * from batch_merged"))
batch_merged <- sqldf(c("update batch_merged set winning = 'het' where Heterophily_Count = Agents_Count", "select * from batch_merged"))
batch_merged <- sqldf(c("update batch_merged set winning = 'pre' where Preferential_Count = Agents_Count", "select * from batch_merged"))
winning <- sqldf("select OptionGroup, sum(CASE WHEN winning='hom' THEN 1 ELSE 0 END) as homophily, sum(CASE WHEN winning='het' THEN 1 ELSE 0 END) as heterophily, sum(CASE WHEN winning='pre' THEN 1 ELSE 0 END) as preferential, sum(CASE WHEN winning='mix' THEN 1 ELSE 0 END) as mixed from batch_merged group by OptionGroup")
# print.data.frame(winning)
```

我用这条指令创建报告:

knit2html("raport-partC.Rmd","raport-parcC.html")

我的会话信息:

> library(knitr)
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C           
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C       
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.9

loaded via a namespace (and not attached):
[1] evaluate_0.5.5 formatR_1.1    stringr_0.6.2  tools_3.1.1  

任何想法都赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

根据评论,我应该首先正确格式化我的R代码以坚持恒定的字符宽度,而不是编织后 - 如果仍有任何问题 - 手动编辑我的页面和CSS。我在可能的情况下结束这个问题。感谢。