简体   繁体   English

使用knitr / R Markdown的目录中的换行符

[英]Line breaks in directory using knitr/R Markdown

I'm currently working with R Markdown and trying to get the code, results and documentation to one pdf-file with the knit function in the end. 我目前正在与R Markdown合作,并试图将代码,结果和文档保存到一个pdf文件中,最后带有knit函数。

Within in the document, I want to set my directory with the setwd command. 在文档中,我想使用setwd命令设置目录。

setwd("C:/Users/Testuser/Documents/Testfolder/Testsubfolder/Testsubfolder2/Testsubfolder3/Testsubfolder4/Testsubfolder5")

However, the file path exceeds the width of the pdf and there is no line break so part of it is cut off at the right side. 但是,文件路径超出了pdf的宽度,并且没有换行符,因此它的一部分在右侧被切除。 When I try to insert a page break manually, for example by pressing Enter after "Testdubfolder2", I get the following Error message: 当我尝试手动插入分页符时,例如通过在“ Testdubfolder2”之后按Enter键,我收到以下错误消息:

"Fehler in setwd("C:/Users/Testuser/Documents/Testfolder/Testsubfolder/Testsubfolder2/\\n Testsubfolder3/Testsubfolder4/Testsubfolder5") : kann Arbeitsverzeichnis nicht wechseln." “ setwd(” C:/ Users / Testuser / Documents / Testfolder / Testsubfolder / Testsubfolder2 / \\ n Testsubfolder3 / Testsubfolder4 / Testsubfolder5“中的费勒:kann Arbeitsverzeichnis nicht wechseln。

, which in English simply means, that the directory can't be changed. ,英文仅表示无法更改目录。 Is there any way to display the file path over two lines using the knit function? 有什么方法可以使用knit函数在两行上显示文件路径? I'd be grateful for any solution or hint. 对于任何解决方案或提示,我将不胜感激。

You can use file.path to construct paths from multiple subpaths, for example: 您可以使用file.path从多个子路径构造路径,例如:

setwd(file.path(
  "C:/Users/Testuser/Documents",
  "Testfolder/Testsubfolder/Testsubfolder2",
  "Testsubfolder3/Testsubfolder4/Testsubfolder5"
))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM