[R] demo()

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 20 01:06:04 CEST 2006


One variation of this is:

"?" <- function(...) invisible(0)

?"this command illstrates blah, blah"
sin(pi)

rm("?")


On 10/19/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 10/19/2006 6:16 PM, Yurii Aulchenko wrote:
> > Dear All,
> >
> > I am programming a demo for an R package (say, the name is "mydemo"); when
> > I run it, it works perfectly fine.
> >
> > Now is the problem: I would like some explanatory text to appear before
> > the command recorded in mydemo runs. If I use "cat" or "print", the result
> > is not nice: first, the comment appears as the command, and then it is
> > printed out. See what I mean:
>
> There isn't an easy way to do this.  You could write a function that
> returns an invisible result, and pass the comments to it, e.g.
>
> m <- function(...) invisible(0)
>
> m("This command will show a histogram of x:")
>
> and you'll see the call but no result.  Obviously, this is kind of kludgy.
>
> What would be nicer would be if comments in the demo() code were echoed
> to the console, but currently the comments are completely lost.
>
> Duncan Murdoch
> >
> > In mydemo code I have
> >
> > # This command will show a histogram of x:
> > cat("This command will show a histogram of x:\n";
> > hist(x)
> >
> > What appears in the output is something like:
> >
> >> cat("This command will show a histogram of x:\n";
> > This command will show a histogram of x:
> >> hist(x)
> > <<histogram is generated>>
> >
> > What I would like to have as the output is:
> >
> > This command will show a histogram of x:
> >> hist(x)
> > <<histogram is generated>>
> >
> > Could someone suggest me a solution?
> >
> > Yurii
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list