Retaining comments when using `example'
Prof Brian D Ripley
Wed, 28 Jul 1999 06:40:55 +0100 (BST)
On 28 Jul 1999, Peter Dalgaard BSA wrote:
> Douglas Bates <email@example.com> 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
> 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="")
###--- >>> `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'.
so there is more to this than just echoing the comments (including echoing
Brian D. Ripley, firstname.lastname@example.org
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: email@example.com