Simon Kiss
2012-Aug-20 21:03 UTC
[R] Changing line length in Sweave output works for numeric, but not for character vectors
Hi there: I'm preparing a report in RStudio 0.96.330 on a Mac OS. I'm running R 2.15.0 I understand from Ross Ihaka's document (http://www.stat.auckland.ac.nz/~stat782/downloads/Sweave-customisation.pdf) that you can modify the line length of Sweave output by a call to options(wdith=x). This works great for me for numeric output, but not for character vectors that I have to print. The following is some sample code that illustrates my problem. Is there a different way to format character vectors that are stored in R? Yours, Simon Kiss \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} <<echo=TRUE, results=verbatim>>seq(1,100,1) @ <<echo=TRUE, results=verbatim>>options(width=30) @ <<echo=TRUE, results=verbatim>>seq(1,100,1) @ <<echo=TRUE, results=verbatim>>test<-c('The government should do more to advance societys goals, even if that means limiting the freedom and choices of individuals.') @ \end{document} ********************************* Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada N3T 2C9 Cell: +1 905 746 7606 Please avoid sending me Word, PowerPoint or Excel attachments. Sending these documents puts pressure on them to use Microsoft software and helps to deny them any other choice. In effect, you become a buttress of the Microsoft monopoly. This pressure is a major obstacle to the broader adoption of free software. To convert to plain text choose Text Only or Text Document as the Save As Type. Your computer may also have a program to convert to PDF format. Select File, then Print. Scroll through available printers and select the PDF converter. Click on the Print button and enter a name for the PDF file when requested.
Yihui Xie
2012-Aug-20 21:52 UTC
[R] Changing line length in Sweave output works for numeric, but not for character vectors
Two possible solutions: 1. Redefine the LaTeX environment so it allows wrapping (see listings for example); 2. Manually break your long string into shorter pieces and paste() them together, e.g. paste('long', 'long', 'string') 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 Mon, Aug 20, 2012 at 5:03 PM, Simon Kiss <sjkiss at gmail.com> wrote:> Hi there: I'm preparing a report in RStudio 0.96.330 on a Mac OS. I'm running R 2.15.0 > > I understand from Ross Ihaka's document (http://www.stat.auckland.ac.nz/~stat782/downloads/Sweave-customisation.pdf) that you can modify the line length of Sweave output by a call to options(wdith=x). > > This works great for me for numeric output, but not for character vectors that I have to print. The following is some sample code that illustrates my problem. > > Is there a different way to format character vectors that are stored in R? > Yours, Simon Kiss > > \documentclass{article} > > \begin{document} > \SweaveOpts{concordance=TRUE} > > <<echo=TRUE, results=verbatim>>> seq(1,100,1) > @ > > <<echo=TRUE, results=verbatim>>> options(width=30) > @ > <<echo=TRUE, results=verbatim>>> seq(1,100,1) > @ > > <<echo=TRUE, results=verbatim>>> test<-c('The government should do more to advance societys goals, even if that means limiting the freedom and choices of individuals.') > @ > > \end{document} > ********************************* > Simon J. Kiss, PhD > Assistant Professor, Wilfrid Laurier University > 73 George Street > Brantford, Ontario, Canada > N3T 2C9 > Cell: +1 905 746 7606 > > Please avoid sending me Word, PowerPoint or Excel attachments. Sending these documents puts pressure on them to use Microsoft software and helps to deny them any other choice. In effect, you become a buttress of the Microsoft > monopoly. This pressure is a major obstacle to the broader adoption of free software. > > To convert to plain text choose Text Only or Text Document as the Save As Type. Your computer may also have a program to convert to PDF format. Select File, then Print. Scroll through available printers and select the PDF converter. Click on the Print button and enter a name for the PDF file when requested. > > ______________________________________________ > 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.
Enrico Schumann
2012-Aug-21 10:00 UTC
[R] Changing line length in Sweave output works for numeric, but not for character vectors
Hi Simon try strwrap(test) regards, Enrico Am 20.08.2012 23:03, schrieb Simon Kiss:> Hi there: I'm preparing a report in RStudio 0.96.330 on a Mac OS. I'm running R 2.15.0 > > I understand from Ross Ihaka's document (http://www.stat.auckland.ac.nz/~stat782/downloads/Sweave-customisation.pdf) that you can modify the line length of Sweave output by a call to options(wdith=x). > > This works great for me for numeric output, but not for character vectors that I have to print. The following is some sample code that illustrates my problem. > > Is there a different way to format character vectors that are stored in R? > Yours, Simon Kiss > > \documentclass{article} > > \begin{document} > \SweaveOpts{concordance=TRUE} > > <<echo=TRUE, results=verbatim>>> seq(1,100,1) > @ > > <<echo=TRUE, results=verbatim>>> options(width=30) > @ > <<echo=TRUE, results=verbatim>>> seq(1,100,1) > @ > > <<echo=TRUE, results=verbatim>>> test<-c('The government should do more to advance societys goals, even if that means limiting the freedom and choices of individuals.') > @ > > \end{document} > ********************************* > Simon J. Kiss, PhD > Assistant Professor, Wilfrid Laurier University > 73 George Street > Brantford, Ontario, Canada > N3T 2C9 > Cell: +1 905 746 7606 >
Apparently Analagous Threads
- using lapply with recode
- latex(test, collabel=) returns wrong latex code?
- separate elements of a character vector
- Create single vector after looping through multiple data frames with GREP
- cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8