2

I use Lyx (2.1.4) with knitr (1.10.5). I have a lot of trouble having the code chunks respect the width that I tried setting through various ways:

  1. In the chunk options (width=50);
  2. options("width")=50 at the top of my document
  3. opts_chunk$set(width=50) also at the top of my document

The results are always the same:

enter image description here

What am I missing? Any help appreciated.

Edit: I realized that it has to do with the quoted string which won't be broken into several lines. Without long strings, the width setting is respected. (Still, the problem remains unsolved.)

1 Answers1

1

Ok so thanks to Adam's help, I was able to see there actually is a workaround for this. However, it involves a fair bit of tweaking in order to make the chunks appear the same way as my other chunks do. So for now, my solution was to set tidy=FALSE and eval=FALSE in the chunk options, and put this in the chunk:

boxplot(fumeurs$imc, horizontal=TRUE, main="Distribution de 
+    l'indice de masse corporelle", xlab="IMC (Kg/m^2)")

That way, the chunk appears exactly as would another one (that is, without spilling over the margins). Then, in another chunk just after (or just before) this one, I create another one having echo=FALSE as an option, and put into it the R code as it is intended (with the long string unbroken). Kinda dirty, but it seems that it is the best fix that doesn't require a full day of tweaking around.

See the links in Adam's comments to my question if you are willing to go through the listings + hook route, and best of luck to you!