rstudio/rmarkdown-cookbook

Chaptern5.3/Addition

Opened this issue · 1 comments

Hi Yihui,

I am currently writing a book with CRC Press, and I found a lot of advice in your posts and books. Thank you!!!

Recently I had a problem with R output too wide for the CRC PDF format. I followed your advice from Chapter 5.3.;

  • options(width) was not respected (you described this in your book)
  • I did not dare to use the listings package because I was afraid it might impact other parts of my book.

So, I came up with a hack that might be useful for others (or not :) );

library(tidyverse)
print(str(diamonds)) #Output too wide
WideOutputVector=capture.output(str(diamonds))
NarrowOutputVector=strtrim(WideOutputVector, 30)
cat(NarrowOutputVector,sep = "\n")

I thought it might help somebody who has a similar problem as I had.

Best,

Carsten
……………………………………………..
Carsten Lange, Ph.D.
Professor of Economics and Graduate Coordinator
California State University
3801 West Temple Ave.
Pomona, CA 91768
Phone: +1 (909) 869 3843
Email: clange@cpp.edu

Thanks for sharing !