From David.Epstein at warwick.ac.uk  Wed Apr 20 16:17:25 2011
From: David.Epstein at warwick.ac.uk (David.Epstein)
Date: Wed, 20 Apr 2011 07:17:25 -0700 (PDT)
Subject: [Rd] Sweave tokens not in column 1: enhancement request
In-Reply-To: <19886.47241.204068.966260@ridcully.stat.uni-muenchen.de>
References: <1303246784050-3461527.post@n4.nabble.com>
	<19886.47241.204068.966260@ridcully.stat.uni-muenchen.de>
Message-ID: <1303309045106-3463141.post@n4.nabble.com>


Friedrich Leisch-2 wrote:
> 
>>>>>> 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
>   > }
> 
>   
> 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.
> 

Thanks. That is indeed very simple. I should have started this thread in
R-help, as I know there are other users who would like to do this, but I
mistakenly thought that code development would be needed. Is it possible to
somehow transfer the thread to R-help?

Would it not be safer to use [:blank:] or [ \t] instead of [:space:]?
[:space:] allows several symbols apart from space and tab, and this might
cause trouble?

Is it possible to put something into the .Rnw file with the same effect, or
do you HAVE to work from outside Sweave?
Thanks
David

--
View this message in context: http://r.789695.n4.nabble.com/Sweave-tokens-not-in-column-1-enhancement-request-tp3461527p3463141.html
Sent from the R devel mailing list archive at Nabble.com.



[Rd] Sweave tokens not in column 1: enhancement request
David.Epstein