Question: write an R script with help information available to the user
On Sun, Feb 3, 2013 at 1:50 AM, Bert Gunter <gunter.berton at gene.com> wrote:
A related approach which, if memory serves, was originally in S eons ago, is to define a "doc" attribute of any function (or object, for that matter) that you wish to document that contains text for documentation and a doc() function of the form: doc <- function(obj) cat(attr(obj,"doc")) used as:
f- function(x) NULL attr(f,"doc") <- "Some text\n\n" doc(f) doc(f)
Some text This is pretty primitive, but I suppose you could instead have the attribute point to something like an HTML file and the doc() function open it in a web browser, which is basically what R's built-in package document system does anyway. Except you wouldn't have to build a package and don't have to learn or follow R's procedures. Which means you don't get R's standardization and organization and no one but a private bunch of users will be able to use your function. But maybe that's sufficient for your needs.
To further build on this try the above idea using the comment function:
f <- function() NULL comment(f) <- "Help goes here" comment(f)
[1] "Help goes here" or combine it with the redefinition of ? like like this: `?` <- function(...) if (!is.null(doc <- comment(get(match.call()[[2]])))) cat(doc, "\n") else help(...) ?f # displays: Help goes here ?dim # normal help -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com