[R] Setting width in batch mode
Friedrich.Leisch@tuwien.ac.at
Friedrich.Leisch at tuwien.ac.at
Fri Sep 9 08:34:15 CEST 2005
>>>>> 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 Wien Fax: (+43 1) 58801 10798
Wiedner Hauptstraße 8-10/1071
A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch
More information about the R-help
mailing list