knitr到PDF未包装注释

knitr到PDF未包装注释,r,pdf,r-markdown,knitr,margin,R,Pdf,R Markdown,Knitr,Margin,当尝试将我的Rmarkdown文件编织成PDF时,knitr似乎没有包装注释,文本只是超出了PDF页边距 我尝试过指定几个参数,但似乎没有任何效果 --- title: "Demo margin" output: pdf_document --- ```{r setup, include=FALSE} options(width=80) knitr::opts_chunk$set(echo = TRUE,out.width = 40, tidy=T, tidy.opts=list(width.

当尝试将我的Rmarkdown文件编织成PDF时,
knitr
似乎没有包装注释,文本只是超出了PDF页边距

我尝试过指定几个参数,但似乎没有任何效果

---
title: "Demo margin"
output: pdf_document
---

```{r setup, include=FALSE}
options(width=80)
knitr::opts_chunk$set(echo = TRUE,out.width = 40, tidy=T, tidy.opts=list(width.cutoff=60))
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars, out.width=80, tidy = 'formatR', tidy.opts = list(blank = FALSE, width.cutoff = 60)}
summary(cars)
#very very very very very very very very very very very very very very very very very very very very very very very very incredibly very long comment
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

我如何才能让knitr将评论包装在页边空白处?

我也遇到了同样的问题,即使进行了详尽的搜索,也没有找到其他解决方案,除了以下两种方法:

  • 手动将注释拆分为较短的行
  • 使用paste0(“foo…”,“…bar”)

我猜您没有安装格式化程序包。如果是这种情况,您需要
安装.packages('format')
。以下是我在电脑上得到的信息:


在安装R v4.0.0并重新安装软件包后,此问题已得到修复

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                       LC_TIME=English_Australia.1252    

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

other attached packages:
[1] formatR_1.7

loaded via a namespace (and not attached):
 [1] compiler_4.0.0  htmltools_0.4.0 tools_4.0.0     yaml_2.2.1      Rcpp_1.0.4.6    rmarkdown_2.1   knitr_1.28      xfun_0.13       digest_0.6.25   rlang_0.4.6     evaluate_0.14 

我已经安装并启动了库,但仍然存在相同的问题。请在Rmd文档的代码块中放入
library(formatar)
,以验证您是否已成功安装Formatar。是的,我这样做了,没有任何区别,我只是再次尝试,我获得了相同的结果。这一定是另一个问题……这很奇怪。虽然我相信R3.6.1应该可以工作,但它不是R的最新版本。也许在黑暗中盲目地升级R并重试……到目前为止运气不好,我已经重新安装了R和所有软件包,仍然存在相同的问题。我也可以在其他刚刚安装了新的R的笔记本电脑上复制它。是Windows还是MiKTeX的原因?
> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                       LC_TIME=English_Australia.1252    

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

other attached packages:
[1] formatR_1.7

loaded via a namespace (and not attached):
 [1] compiler_4.0.0  htmltools_0.4.0 tools_4.0.0     yaml_2.2.1      Rcpp_1.0.4.6    rmarkdown_2.1   knitr_1.28      xfun_0.13       digest_0.6.25   rlang_0.4.6     evaluate_0.14