From murdoch at stats.uwo.ca  Tue Nov 30 13:10:48 2004
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue Nov 30 13:10:07 2004
Subject: [Rd] Re: a better "source(echo=TRUE)" {was "....how to pause...."}
In-Reply-To: <16812.24240.754731.879678@gargle.gargle.HOWL>
References: <b68812e704112708422b5228a4@mail.gmail.com>
	<1101582479.13352.37.camel@horizons.localdomain>
	<b68812e704112718032d3cf7d8@mail.gmail.com>
	<vuhiq095lke0trblge8161b3dakaubg776@4ax.com>
	<2kpjq0p9bq1i8b2258rl71bds4k9bg83fq@4ax.com>
	<16812.24240.754731.879678@gargle.gargle.HOWL>
Message-ID: <r9ooq098cm6snh7ku5cuvjded9ltpfndrv@4ax.com>

On Tue, 30 Nov 2004 12:51:12 +0100, Martin Maechler
<maechler@stat.math.ethz.ch> wrote:

>>>>>> "Duncan" == Duncan Murdoch <murdoch@stats.uwo.ca>
>>>>>>     on Sun, 28 Nov 2004 10:25:24 -0500 writes:
>
>    Duncan> <........>
>    Duncan> <........>
>
>    Duncan> We already have code to source() from the clipboard, and it could
>    Duncan> address the problems above, but:
>
>    Duncan> - Source with echo=T doesn't echo, it deparses, so some comments are
>    Duncan> lost, formatting is changed, etc.
>
>yes, and we would have liked to have an alternative "source()"
>for a *very* long time...
>Examples where I "hate" the non-echo (i.e. the loss of all
>comments and own-intended formatting) is when you use it for
>demos, etc, notably in R's own  demo() and example() functions.
>
>But to do this might be more tricky than at first thought:
>Of course you can readLines() the source file and writeLines()
>them to whatever your console is. The slightly difficult thing
>is to "see" which junks to ``send to R'' , i.e. to parse() and eval().
>The basic problem seems to see when expressions are complete.
>
>Maybe we should / could think about enhancing parse() {or a new
>function with extended behavior} such that it would not only
>return the parse()d expressions, but also indices (byte or even
>line counters) to the source text, indicating where each of the
>expression started and ended.
>
>That way I could see a way to proceed.

I started trying to do that last summer, but ran out of time before I
finished, and haven't got anything new done this fall.  I think the
part you describe above was done, but what I hadn't worked out were
the details of where the source would be stored.  For example, if my
example was

# Comment 1
x <- 1
# Comment 2
y <- 2
# Comment 3

do I store the source in one place with references from each line, or
break it up into separate pieces (two or five),  or just refer to the
file these lines came from?  I was trying to do it by storing the
source or a filename reference in one place with offsets to it from
each line, but didn't get done.

Duncan Murdoch


[Rd] Re: a better "source(echo=TRUE)" {was "....how to pause...."}
Duncan Murdoch