Re: [Rd] Source references from the parser

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Sun 26 Nov 2006 - 08:02:02 GMT

On 11/25/06, Duncan Murdoch <murdoch@stats.uwo.ca> wrote:
> On 11/25/2006 11:00 PM, Deepayan Sarkar wrote:
> > On 11/25/06, Duncan Murdoch <murdoch@stats.uwo.ca> wrote:
> >> On 11/25/2006 3:12 PM, Deepayan Sarkar wrote:
> >>> On 11/25/06, Duncan Murdoch <murdoch@stats.uwo.ca> wrote:
> >>>> I have just committed some changes to R-devel (which will become R 2.5.0
> >>>> next spring) to add source references to parsed R code. Here's a
> >>>> description of the scheme:

[snipped]

> >>>> Comments and problem reports are welcome.
> >>> I haven't tested this, but the idea seems useful. Will this have any
> >>> effect on code parsed using parse(text = "...")? Can it be extended to
> >>> have some such effect? I ask because this is relevant in the context
> >>> of Sweave, where I have always wanted the ability to retain the
> >>> original formatting. I'm currently testing a patch that allows me to
> >>> do this specifically for Sweave, but a more general solution is
> >>> obviously preferable.
> >> I've just added the capability to Sweave. I haven't committed yet,
> >> because I think it's important that authors can choose whether or not to
> >> turn this on. Could you let me know your typical workflow with Sweave,
> >> whether you'd like this to default to on or off, and where you'd expect
> >> to change the default?
> >
> > I would like it as an option to the RweaveLatex driver (and perhaps
> > others). In terms of changing the API, this is as simple as adding an
> > argument to the 'RweaveLatexSetup' function.
> >
> > In the case of my patch, the default is off, and is turned on by
> >
> > <<...,src=TRUE>>
> > ...
> > @
> >
> > To make this the global default, one can do
> >
> > \SweaveOpts{src=TRUE}
> >
> > etc. (the name 'src' is not necessarily the best, some variant of
> > 'keep.source' might be more intuitive.)
>
> This is now committed.

Working great, thanks. The behaviour of comments is interesting (and fortuitous for me), in that top level comments get associated with the expression that follows it and comments at the end of a chunk are ignored. Is this intended and can I expect it to remain unchanged? (My chunks currently tend to end with a blank comment to work around a bug in ESS, and I would rather not fix them all.)

> I used keep.source, exactly the same as the option() that controls this
> behaviour in other places.

>

> I decided to set the default to TRUE. This means vignettes will all
> look different in R-devel. The simplest way to get the previous
> appearance is to put in
>

> \SweaveOpts{keep.source=FALSE}
>

> but in most cases I think people will want the new behaviour. It's only
> bad if the code was badly formatted or contained comments you don't want
> to show up in the final document. I looked through the grid package
> vignettes, and only saw about half a dozen places where I thought the
> formatting needed tweaking.

Fine with me (although I suspect R's deparse will often produce more readable code if the original wasn't written in an editor with smart indentation).

-Deepayan



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun Nov 26 19:05:14 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 26 Nov 2006 - 12:30:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.