[R] Setting width in batch mode

Jonathan Dushoff dushoff at eno.princeton.edu
Thu Sep 8 21:01:23 CEST 2005


As instructed, I have spent a long time searching the web for an answer
to this question.

I am trying to use Sweave to produce lecture slides, and have the
problem that I can't control the formatting of my R source.  Setting
options(width), as recommended in this forum, works fine on the R
_output_, but seems to have unpredictable effects on the echoing of the
source code.

If I try setting options(width) directly in R, I note that it has _no_
effect on echoed source code, whereas Sweave does sometimes break source
code, but not predictably, and not to the same width as output code.

I would be happy with any method of manually or automatically
controlling the line width of Sweave source, using R, Sweave or LaTeX
options.  Making the font smaller does not count, though; I want to
break the lines.

Any help is appreciated.

An example of Sweave input and output is appended.

The last break is right, while the others are too late.

Jonathan Dushoff

----------------------------------------------------------------------
bug.rnw

<<>>=
options(width=55)
data(state)
data.frame(area=mean(state.area),   pop=mean(state.pop),   hop=mean(state.area))
c(medianarea=median(state.area),   medianpop=median(state.pop))
c(medianarea=median(median(state.area)),   medianpop=median(state.pop))
@

----------------------------------------------------------------------
bug.tex

\begin{Schunk}
\begin{Sinput}
> options(width = 55)
> data(state)
> data.frame(area = mean(state.area), pop = mean(state.pop), 
+     hop = mean(state.area))
\end{Sinput}
\begin{Soutput}
       area     pop      hop
1 72367.98 4246420 72367.98

\end{Soutput}
\begin{Sinput}
> c(medianarea = median(state.area), medianpop = median(state.pop))
\end{Sinput}
\begin{Soutput}
medianarea  medianpop
      56222    2838500

\end{Soutput}
\begin{Sinput}
> c(medianarea = median(median(state.area)), 
+     medianpop = median(state.pop))
\end{Sinput}
\begin{Soutput}
medianarea  medianpop
      56222    2838500

\end{Soutput}
\end{Schunk}




More information about the R-help mailing list