簡體   English   中英

knitr to PDF 不包裝評論

[英]knitr to PDF not wrapping comments

當嘗試將我的 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)
```

在此處輸入圖像描述

> sessionInfo()
R version 3.6.1 (2019-07-05)
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   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

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

loaded via a namespace (and not attached):
 [1] compiler_3.6.1  htmltools_0.4.0 tools_3.6.1     yaml_2.2.0      Rcpp_1.0.3     
 [6] rmarkdown_2.0   knitr_1.26      xfun_0.11       digest_0.6.23   rlang_0.4.2    
[11] evaluate_0.14 

我怎樣才能讓knitr將評論包裝在邊距內?

我的猜測是你沒有安裝formatR包。 如果是這種情況,您需要install.packages('formatR') 這是我在電腦上得到的:

由 formatR 重新包裝的評論

我遇到了同樣的問題,即使經過詳盡的搜索,也沒有找到其他解決方案:

  • 手動將注釋分成較短的行
  • 使用 paste0("foo ... ", "... bar")

安裝 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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM