From ripley@stats.ox.ac.uk  Wed Jul 28 06:40:55 1999
From: ripley@stats.ox.ac.uk (Prof Brian D Ripley)
Date: Wed, 28 Jul 1999 06:40:55 +0100 (BST)
Subject: Retaining comments when using `example'
In-Reply-To: <x23dy9d5pj.fsf@blueberry.kubism.ku.dk>
Message-ID: <Pine.GSO.4.05.9907280626520.11506-100000@auk.stats>

On 28 Jul 1999, Peter Dalgaard BSA wrote:

> Douglas Bates <bates@stat.wisc.edu> writes:
> 
> > Is there a way to retain the comments?  I notice that `example' ends up
> > calling the `source' function to do the actual running of the code.
> 
> Yeowch! This was not easy with the old comment-as-attribute model, and
> it certainly did not get easier with the new keep-function-source
> semantics.
> 
> The real trouble is - I suspect - an ancient one, inherited from S:
> 
> 	source() doesn't
> 
> I.e. it does not work in the same way as the source command in a shell
> would, interpreting a file as if it had been lines entered on the
> command line, with some provision for skipping back to interactive
> mode if there's an error. Rather, it parses the entire file (and
> syntax checks it) and runs the resulting parsed expression. 

Ah, but S can use options(echo=T) to do the echoing, rather than the
complicated code R has, and if echo=T S's source runs a loop running dput
on the expressions. And S _does_ echo the comments.

> Perhaps we need a "real" source()?

Yes, but let's try smaller things first.

Why does options(echo=TRUE) do nothing in R?
Since if echoing is actually set (iff R thinks it is non-interactive)
comments are echoed, it seems we do have the mechanisms needed in place.

_If_ this worked Doug would have noticed that there are too many comments
in the R-ex files: running that example in S-PLUS gives

> options(echo=T, prompt="")
> source("/ext/R/R-devel/library/base/R-ex/col.R")
###--- >>> `col' <<<----- Column Indexes
## alias         help(col)
##___ Examples ___:
# extract an off-diagonal of a matrix
ma <- matrix(1:12, 3, 4)
ma[row(ma) == col(ma) + 1]
# create an identity 5-by-5 matrix
x <- matrix(0, nr = 5, nc = 5)
x[row(x) == col(x)] <- 1
## Keywords: 'array'.
vector("end.of.file",0)

so there is more to this than just echoing the comments (including echoing
the output).


-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Retaining comments when using `example'
Prof Brian D Ripley