Re: [R] Setting width in batch mode

2005-09-09 Thread Friedrich . Leisch
 On Thu, 8 Sep 2005 15:01:23 -0400 (EDT),
 Jonathan Dushoff (JD) wrote:

   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.

The deparser of R only *tries* to break lines at the given cutoff
(Sweave uses 0.75*getOption(width) for input lines), so you
soemtimes have to play a little bit, and yes, results are somewhat
unpredictable. After storing your code in file ex1.R I get:

R expr=parse(ex1.R)
R length(expr)
[1] 5

R for(n in 1:length(expr)) print(deparse(expr[[n]], width.cutoff=.75*55))
[1] options(width = 55)
[1] data(state)
[1] data.frame(area = mean(state.area), pop = mean(state.pop), 
[2] hop = mean(state.area))
[1] c(medianarea = median(state.area), medianpop = median(state.pop))
[1] c(medianarea = median(median(state.area)), 
[2] medianpop = median(state.pop)) 

R for(n in 1:length(expr)) print(deparse(expr[[n]], width.cutoff=.75*45))
[1] options(width = 55)
[1] data(state)
[1] data.frame(area = mean(state.area),   
[2] pop = mean(state.pop), hop = mean(state.area))
[1] c(medianarea = median(state.area), 
[2] medianpop = median(state.pop)) 
[1] c(medianarea = median(median(state.area)), 
[2] medianpop = median(state.pop)) 


I know that's not exactly the answer you were looking for, but that's
the way it is. I'll add a sentence or two to the FAQ.

Best,

-- 
---
Friedrich Leisch 
Institut für Statistik Tel: (+43 1) 58801 10715
Technische Universität WienFax: (+43 1) 58801 10798
Wiedner Hauptstraße 8-10/1071
A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Setting width in batch mode

2005-09-08 Thread Jonathan Dushoff
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
  562222838500

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

\end{Soutput}
\end{Schunk}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html