[英]R Markdown Knitr to PDF Code Outside Margin
I want to attach the entirety of my code chunks at the end of my document.我想在文档末尾附上我的全部代码块。 The code includes plots, inserted graphics, calculations and so forth.
代码包括绘图、插入图形、计算等。 It's long.
它很长。 This is after I have run the relevant code in its respective chapters.
这是在我运行了相应章节中的相关代码之后。 At this point, I don't want the code to generate any results, but simply show the code so that others can check on what I have done.
在这一点上,我不希望代码生成任何结果,而只是简单地显示代码,以便其他人可以检查我所做的事情。
Here is an example of part of the code:以下是部分代码的示例:
shapefile1 <- readOGR("./Folder1/Folder2/Folder3", layer = "TM_WORLD_BORDERS-0.3") # Read in world shapefile
When I compile, it shows up outside the margin that I have set for my document in the YAML header like this当我编译时,它显示在我在 YAML 标头中为我的文档设置的边距之外,如下所示
geometry: top=2.5cm, bottom=2cm, left=3cm, right=3.5cm
I have tried the following solutions:我尝试了以下解决方案:
Option 1:选项 1:
In R markdown in RStudio, how can I prevent the source code from running off a pdf page? 在 RStudio 中的 R markdown 中,如何防止源代码从 pdf 页面运行?
```{r, eval=FALSE, tidy=TRUE, tidy.opts=list(width.cutoff=60)}
```
Option 2:选项 2:
https://tex.stackexchange.com/questions/133810/knitr-plotting-outside-margin https://tex.stackexchange.com/questions/133810/knitr-plotting-outside-margin
```{r, eval=FALSE, out.width=".9\\paperwidth"}
```
Neither works for me.都不适合我。 The only other thing I can think of is manually making the code lines shorter, but I'm sure that can't be the best option.
我唯一能想到的另一件事是手动缩短代码行,但我确信这不是最好的选择。 How is this done?
这是怎么做的?
This happens to me when I use "pdflatex" as the Latex Engine in R Studio.当我在 R Studio 中使用“pdflatex”作为 Latex 引擎时,就会发生这种情况。 When I change to "xelatex", this doesn't happen anymore.
当我更改为“xelatex”时,这种情况不再发生。 But I also need this code chunk in the beggining of the markdown:
但我在降价开始时也需要这个代码块:
library(knitr)
# Set so that long lines in R will be wrapped:
opts_chunk$set(tidy.opts=list(width.cutoff=40),tidy=TRUE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.