[R] commenting demos

Martin Maechler maechler at stat.math.ethz.ch
Mon Oct 27 15:04:20 CET 2003


>>>>> "Olivia" == Olivia Lau <olau at fas.harvard.edu>
>>>>>     on Sun, 26 Oct 2003 00:49:45 -0400 writes:

    Olivia> Hi, Is there a way to make demo() print comments
    Olivia> along with the code and output?

not so easily.  The same applies to  example(.).
Both demo(.) and example(.) end up calling source(.) which
itself relies on
 1)  parse(...)
 2)  eval(...)

parse(.) in R (currently) drops all comments, so they are "lost"
very early in source() and hence everything else that calls source().

Many have wanted a version of source() {and hence demo() and
example() and ....} that would be able to echo all comments; but
this is not really easy: Somehow you need a version of parse()
{think of multiline statements!} to do this properly.

    Olivia> For example, if I use something like
    Olivia> readline("..."), demo prints both readline("...")
    Olivia> and ...; as far as I can tell, this is also true of
    Olivia> print() and cat().  I just want students to stop and
    Olivia> think about every command in my demo scripts.

One way, not using demo() would be to ask them to read the R
script (e.g. in winedt or emacs) and *send* the commands to a
running R themselves.

But's that's a quite different approach {than demo()}.
Martin

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><




More information about the R-help mailing list