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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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. Perhaps we need a "real" source()? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._