注释在 RMarkdown 中拆分为多行



我正在用RMarkdown编写一个文档,有时我想在我的代码块中包含注释,这些注释显示在PDF中,如下所示:

vector <- 1:4
# finds the mean of these values
mean(vector)
## [1] 2.5

但是,当我编织PDF(或HTML文档)时,它会将注释分解为一个单词行,如下所示:

vector <- 1:4
# finds
# the
# mean
# of
# these
# values
mean(vector)
## [1] 2.5

这真的很烦人,它使我的文档比它们需要的要长得多。我该如何解决它?

编辑:更新了所有软件包;这是会话信息:

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] abind_1.4-5
loaded via a namespace (and not attached):
 [1] backports_1.0.5 magrittr_1.5    rprojroot_1.2   htmltools_0.3.5 tools_3.3.1     yaml_2.1.14     Rcpp_0.12.9     stringi_1.1.2  
 [9] rmarkdown_1.3   knitr_1.15.1    stringr_1.1.0   digest_0.6.12   evaluate_0.10  

这可能是由于 knitr/formattR 的代码整理引起的,width.cutoff集太小。您可以通过以下方式检查区块选项:

opts_chunk$get()

也许设置一个更大的width.cutoff; formatR将尝试确保代码中没有一行字符数超过此字符数:

opts_chunk$set(tidy=T‌​RUE,
    tidy.opts=list(width.cutoff=60))

最新更新