Sometimes I get to make an R code chunk (in Sweave) which is longer then the margins of the page. Is there a way to force it to "go to the next line" once that happens?
Here is a simple example of that happening:
\documentclass[a4paper]{article}
\usepackage{Sweave}
\DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=2em,
frame=single}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em,
frame=single}
\title{Sweave with boxes}
\begin{document}
\maketitle
<<echo=FALSE>>=
options(width=60)
@
Here is an example of a code chunk followed by an output chunk,
both enclosed in boxes.
<<>>=
print(rnorm(99))
@
<<>>=
print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
@
\end{document}
And here is the resulting tex file:
\documentclass[a4paper]{article}
\usepackage{Sweave}
\usepackage{listings}
\DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=2em,
frame=single}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em,
frame=single}
\lstset{breaklines=true}
\title{Sweave with boxes}
\begin{document}
\maketitle
Here is an example of a code chunk followed by an output chunk,
both enclosed in boxes.
\begin{Schunk}
\begin{Sinput}
> print(rnorm(99))
\end{Sinput}
\begin{Soutput}
[1] 0.36727922 0.25285078 -0.70328574 1.71655755
[5] 0.30473595 -0.11520852 -1.36801956 0.49911603
[9] 0.53733672 -1.26568069 0.33561173 0.93723468
[13] 2.41014561 0.09806442 -1.34404921 -0.98648477
[85] -0.40756482 -1.39450719 0.59070374 -1.09769309
[89] -1.43169931 0.87022380 -0.27047513 0.67547425
[93] 0.87007650 -0.08518324 -0.11001269 -0.91401310
[97] 0.25477667 -1.52641463 0.22896815
\end{Soutput}
\end{Schunk}
\begin{Schunk}
\begin{Sinput}
> print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
\end{Sinput}
\begin{Soutput}
[1] "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
\end{Soutput}
\end{Schunk}
\end{document}
Update, here is a simpler tex situation that I would just as well like to solve:
\begin{Schunk}
\begin{Soutput}
Some Table
Model 1: SCIM_2_total ~ (I(AMS_2_total^3) + I(AMS_2_total^2) + AMS_2_total) + fox
Model 2: SCIM_2_total ~ (I(AMS_2_total^2) + AMS_2_total) + fox
\end{Soutput}
\end{Schunk}



"or(. Could you come up with a more "natural" example that hangs out into the margin? – Sharpie Jan 18 '12 at 20:24