Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control width of knitr output for columns in sweave documents

Tags:

r

knitr

sweave

According to FAQ.7 and Example.038, I should be able to control my width through global options options(width=40) or chunk options tidy.opts(width.cutoff=40). However, the text still runs off the gray box, and in my current case where I have two-column beamer slides. the source code runs into the next column. Is there anything else I can do besides turning off tidy tidy=FALSE and manually setting the breaks in my code?

Minimal working example:

\documentclass[8pt]{beamer}
\begin{document}
\begin{frame}[fragile]
<<>>=
library(reshape2)
options(width=38)
@ 
\begin{columns}[t]
  \column{.5\textwidth}
  <<>>=
  dataframe <- data.frame(Column1=1:10,Column2=1:10,Variable=1:10,Value=1:10)
  @ 
  \column{.5\textwidth}
  <<>>=
  dataframe <- melt(dataframe,
  id.vars=c("Column1","Column2"),
  variable.name="Variable",
  value.name="Value")
  @ 
\end{columns}
\end{frame}
\end{document}

Output (problem is that columns run together):

enter image description here

like image 506
hatmatrix Avatar asked Mar 10 '14 01:03

hatmatrix


1 Answers

Options should be passed like this:

<<echo=FALSE>>=
opts_chunk$set(comment="", message=FALSE,tidy.opts=list(keep.blank.line=TRUE, width.cutoff=120),options(width=100), cache=TRUE,fig.align='center',fig.height=6, fig.width=10,fig.path='figure/beamer-',fig.show='hold',size='footnotesize', cache=TRUE)
@

And here you specify width.cutoff for code and width for r results.

like image 160
Marcin Kosiński Avatar answered Oct 31 '22 06:10

Marcin Kosiński