1

I have an Rmd script that reads in a file for processing. As a part of the report, I am printing the path to that file for clarity and consistency. When that file is heavily nested (inside a number of folders) the length of the file path becomes too long to print on a single line. Is there a way to force a word break in the Rmd code that will print the path on 2 lines if it is longer than can be shown on a single line?

Example:

---
title: "Test"
author: "Test"
date: "10/13/2016"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = TRUE)
```

#Set Variable
```{r VarDef}
File <- "~/Documents/Data/StudyData/WGS/FolderName1/FolderName2/FolderName3/ExtraLongBacteriaName_Details_pass_2D.fasta"
```


This is a test RMD file as an example. The file name causing issue is:

**`r File`**

I would like to be able to have this name break at the end of the page and continue on a second line.
EpiBlake
  • 177
  • 1
  • 12
  • this might help: http://tex.stackexchange.com/questions/100088/r-code-linebreaks-and-code-highlighting-in-knitr – maRtin Oct 13 '16 at 21:30
  • @maRtin Thank you for your response. If I understand that example correctly, it uses tidy (which is in my toy example) and relies on splits on space characters for line breaks. Do you know how to make this split on / characters? – EpiBlake Oct 13 '16 at 21:33
  • Right, this might work better for you then: http://stackoverflow.com/questions/24020617/textwrapping-long-string-in-knitr-output-rstudio – maRtin Oct 13 '16 at 21:47
  • That link has the perfect solution. Thank you! – EpiBlake Oct 13 '16 at 22:10

1 Answers1

0

I had the same problem while trying to knit an R markdown file to PDF. None of the code solutions work, but I noticed that R leaves a blank space in the line number when the code is wrapped (e.g. line 345, blank space, line 346). This means the line is wrapped.

You can unwrap it by clicking enter at the beginning of the line without a number. The new lines are 345, 346 and 347)

I did this for the whole code and now it knits nicely!