1
votes

I'm trouble getting Rmarkdown to text wrap when it reaches a certain line length. Currently, it adds a horizontal scrollbar, but ideally it would just wrap the text.

I have tried using

knitr::opts_chunk$set(tidy=TRUE,
tidy.opts=list(width.cutoff=60))

It works on some code chunks but not others.

My first code chunk, it works. (code is on the left, output is on the right)

The comment in this photo properly text wraps

But later in the document, knitr no longer wraps comments. (code is on the left, output is on the right)

The comment forces a horizontal scrollbar

How can I force knitr to wrap all the code chunks, including the comments?

1

1 Answers

1
votes

That's because an inline comment (after a line of code) can't be wrapped, otherwise the code will be invalid. For example, you can't wrap

1 + 1  # this is a comment

as

1 + 1  # this is
a comment

If you want comments to be wrapped, you have to write whole lines of comments.