From Friedrich.Leisch at boku.ac.at  Wed Apr 20 12:42:17 2011
From: Friedrich.Leisch at boku.ac.at (Friedrich Leisch)
Date: Wed, 20 Apr 2011 12:42:17 +0200
Subject: [Rd] Sweave tokens not in column 1: enhancement request
In-Reply-To: <1303246784050-3461527.post@n4.nabble.com>
References: <1303246784050-3461527.post@n4.nabble.com>
Message-ID: <19886.47241.204068.966260@ridcully.stat.uni-muenchen.de>

>>>>> On Tue, 19 Apr 2011 13:59:44 -0700 (PDT),
>>>>> David Epstein (DE) wrote:

  > When I re-use a code chunk in Sweave, together with keep.source=TRUE, I would
  > like to follow usual programming conventions in which the amount of white
  > space on the left indicates logical structure. It seems that one can't do
  > this in Sweave, or am I wrong?

  > for (i in ind) {
  >     do such-and-such and then
  >     <<code chunk 20>>
  >     do something-else
  > }

  > Sweave will say that << is an error. Would it be difficult to change Sweave
  > so that formatting in the conventional way becomes possible? I'm thinking
  > both of the .Rnw file and of the final output in the .pdf or .ps file.

Not difficult at all, that's a trivial change:

  MySyntax <- utils::SweaveSyntaxNoweb
  MySyntax$coderef <- "^[[:space:]]*<<(.*)>>.*"
  Sweave("test.Rnw", syntax=MySyntax)

should do what you want. That code references need to start in column 1
is inherited from noweb, not sure if we really need it. Cannot think
of a situation where the above regular expression appears in valid R
code, but perhaps I am overlooking something.

Best,
Fritz



[Rd] Sweave tokens not in column 1: enhancement request
Friedrich Leisch