[R] Seeming failure of options(width=60)

Yihui Xie xie at yihui.name
Mon Mar 26 23:45:17 CEST 2012

knitr gives you full power to do whatever you want with the output, so
you can use all sorts of LaTeX environments or packages to customize
your output. For example, in this case, I think listings may be
helpful; it has an option breaklines=true which allows you to break

Here is a minimal example: https://gist.github.com/2209775 (output:

The basic idea is to call render_listings() to set up output hooks
using the listings package, and modify the error hook

For font size, yes the listings package is quite flexible as well.
Again, you are free to customize the output with any LaTeX
environments, not necessarily limited to listings.

Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

On Mon, Mar 26, 2012 at 8:30 AM, John C Nash <nashjc at uottawa.ca> wrote:
> Yihui is correct that an error is generated. I should have mentioned that this is
> something I wanted to show in a vignette, and I got 103 characters as the length of the
> maximal line from a sink() file. Yihui's use of nchar is more elegant.
> Thus the question remains of how to avoid margin over-run in the vignette output. I've
> seen this several times now, and there are some postings on the web that look like they
> are from the same source, but apart from options(width = ...) not found a solution. I can
> edit the Sweave output .tex file, but that seems a bit drastic and contrary to the spirit
> of reproducible research tools.
> Possibilities:
>  - Can margins in Sweave (or knitr) be forced?
>  - Can the fixed width font size be adjusted easily?
> JN

More information about the R-help mailing list