Retaining comments when using `example'

Douglas Bates bates@stat.wisc.edu
27 Jul 1999 17:41:48 -0500


I find the `example' function, used to run the examples from a help
page, to be very useful.  It would be even more useful if I could find
a way to have the comments echoed along with the example code.

For example, the example section of col.Rd from the base library reads

 # 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

but example(col) produces

 R> example(col)

 col> ma <- matrix(1:12, 3, 4)

 col> ma[row(ma) == col(ma) + 1]
 [1] 2 6

 col> x <- matrix(0, nr = 5, nc = 5)

 col> x[row(x) == col(x)] <- 1

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.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._