[R] issues with Sweave and inclusion of graphics in a document

Friedrich Leisch Friedrich.Leisch at stat.uni-muenchen.de
Sat Aug 26 15:05:47 CEST 2006


>>>>> On Sat, 26 Aug 2006 05:38:58 -0700 (PDT),
>>>>> Thomas Harte (TH) wrote:


  > hallo, friedrich, and thanks for your reply.

  > if i Stangle your code i get:

  >         sp<- make.ar.1(alpha=.5, n=800)
  >         plot(sp, type="l", col="blue")

  > whereas if i Stangle my code, i get:

  >         width<- 20; height<- 5
  >         x11(width=width, height=height)
  >         sp<- make.ar.1(alpha=.5, n=800)
  >         plot(sp, type="l", col="blue")
  >         savePlotAsPdf("ar.pdf")

  > this, i think, is the problem in a nutshell.

  > i want my R code to look like this because i (often) want to open
  > a separate device (for example, to have specific dimensions as
  > above) and i may wish to save its contents. on the other hand, i
  > may not wish to save a device's contents: i may wish to open
  > several devices for comparison purposes and i may wish to save
  > only certain devices, in keeping with the Sweave options
  > echo=false and results=hide.

  > if i use your, admittedly uncomplicated, code chunk, then i am
  > limited to seeing the output in the final document. i can't cut
  > and paste the code chunk into an R session and see the results as
  > i wish to see them before saving.

  > currently for each project i work on, i usually end up with a very
  > lengthy .R file with all the code (and embedded mathematical
  > annotation in LaTeX), and then i have to write a set of notes or a
  > report in LaTeX duplicating or expanding on the mathematics. i'm
  > hoping to supplant this, rather inefficient, method with a single
  > .Rnw file and the use of Sweave. this, i believe, is what Sweave
  > was designed to do. but i do wish to write my R code (warts and
  > all) the way that i want to in the .Rnw file and only include the
  > output (graphics or text) of certain parts of that code in the
  > document. i hope that seems reasonable.

  > perhaps i was not clear, or succinct enough, in my original post
  > (i tried to get the point across by providing example .Rnw files,
  > but i'm aware that it's asking a lot to wade through a lengthy
  > example to retrieve a point).

OK, no I think I understand what you want: running the *tangled* code
should open windows with the same height/width ratio as in the Latex
document, right? Your first posting suggested to me more the other way
round ...

No, what you want is currently not directly possible with Sweave, you
will have to use workarounds like the one you posted. You can even
easily write your own tangle function doing it automatically (Rtangle
is really trivial can be easily adjusted to ones personal needs).

Best,
Fritz



More information about the R-help mailing list