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

Thomas Harte thomas.harte at yahoo.com
Sat Aug 26 19:15:27 CEST 2006



--- Friedrich Leisch <Friedrich.Leisch at stat.uni-muenchen.de> wrote:

> >>>>> 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? 

yes, that is correct. the goal is to develop R code in exactly the same
way as i always do (a monolithic script with lots of inroads into a 
problem, solutions i tried and rejected, helpful pointers to the 
real solution, and so on), but to have a document (.pdf, .ps, whatever)
that goes along with the monolithic script noting all the key points. 
hence, six months after writing the code i want to be able to go back, 
refresh my memory with the document and then delve into the R code
if i have to. 

maintaining both the R code and the LaTeX documentation
in one .Rnw file is the genius of your Sweave package and this is 
what i want to adopt as my standard development methodology.

> Your first posting suggested to me more the other way round ...

mea maxima culpa. 
 
> 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).

thank you for the clarification. i feel a lot less awkward in using
that complicated workaround code ;)

cheers / gruss,

thomas.



More information about the R-help mailing list