Tal Galili
2012-Jan-19 08:24 UTC
[R] Sweave question - Setting Soutput code chunks to stay inside page margins?
Hello all, 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" (in Sweave) once that happens? Here are two cases this happens in the resulting .tex file (one is a "hard" case, and the other is simpler) \begin{Schunk} \begin{Sinput}> print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")\end{Sinput} \begin{Soutput} [1] "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \end{Soutput} \end{Schunk} \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} I understand this can be "fixed" from the r side by doing something that will break lines for outputs, but that will require me to go through any relevant print command and modify it (I rather find a global solution, naturally...) Thanks, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
Yihui Xie
2012-Jan-19 08:47 UTC
[R] Sweave question - Setting Soutput code chunks to stay inside page margins?
Do you have a practical case in which you have to print 114 a's without spaces? I mean this is such an extreme case that is unlikely to happen in real life. As long as you have spaces in your string, it will be easy for LaTeX to wrap long lines, although LaTeX should be able to do it even if the string does not contain spaces. Let me add the SO link for future reference as well: http://stackoverflow.com/q/8907613/559676 Regards, Yihui -- 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 Thu, Jan 19, 2012 at 2:24 AM, Tal Galili <tal.galili at gmail.com> wrote:> Hello all, > > 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" (in Sweave) once that happens? > > Here are two cases this happens in the resulting .tex file (one is a "hard" > case, and the other is simpler) > > \begin{Schunk} > \begin{Sinput} > >> print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") > \end{Sinput} > \begin{Soutput} > [1] "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" > \end{Soutput} > \end{Schunk} > > > \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} > > > I understand this can be "fixed" from the r side by doing something that > will break lines for outputs, but that will require me to go through any > relevant print command and modify it (I rather find a global solution, > naturally...) > > > Thanks, > Tal > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili at gmail.com | ?972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > ---------------------------------------------------------------------------------------------- > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Duncan Murdoch
2012-Jan-19 13:12 UTC
[R] Sweave question - Setting Soutput code chunks to stay inside page margins?
On 12-01-19 3:24 AM, Tal Galili wrote:> Hello all, > > 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" (in Sweave) once that happens?Sweave normally uses a verbatim environment, so you have to arrange this on the R side. Setting options(width=60) works in a lot of cases, but not in your example below. Duncan Murdoch> > Here are two cases this happens in the resulting .tex file (one is a "hard" > case, and the other is simpler) > > \begin{Schunk} > \begin{Sinput} > >> print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") > \end{Sinput} > \begin{Soutput} > [1] "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" > \end{Soutput} > \end{Schunk} > > > \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} > > > I understand this can be "fixed" from the r side by doing something that > will break lines for outputs, but that will require me to go through any > relevant print command and modify it (I rather find a global solution, > naturally...) > > > Thanks, > Tal > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili at gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > ---------------------------------------------------------------------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.