Skip to content

page() (Was: Re: predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall()))

3 messages · Henrik Bengtsson, Brian Ripley

#
Here I think S3 dispatch is very natural.  Try the following:

page <- function(x, method = c("dput", "print"), ...) UseMethod("page")

page.getAnywhere <- function(x, ..., idx=NULL) {
  name <- x$name;
  objects <- x$obj;

  if (length(objects) == 0)
    stop("no object named '", name, "' was found");

  if (is.null(idx)) {
    # Include all non-duplicated objects found
    idx <- (1:length(objects))[!x$dups];
  }

  for (ii in idx) {
    title <- paste(name, " (", x$where[ii], ")", sep="");
    eval(substitute({
      object <- x$obj[[ii]];
      page(object, ...);
    }, list(object=as.name(title))));
  }
}

page.default <- utils::page;

page(getAnywhere("predict.smooth.spline.fit"))

You can have page.function(), page.character(), page.environment(),
etc. and make these call page.default() indirectly.  What I think
would be a very useful add on is to add an argument 'title' for which
you can set/override the title.  Then the "ugly" substitute() calls
could be limited to one specific case; where a "default" object is
passed and no title is set.

If you want to, I could play around with a bit.

/Henrik
On 4/5/06, Kurt Hornik <Kurt.Hornik at wu-wien.ac.at> wrote:
[snip]
#
On Wed, 5 Apr 2006, Henrik Bengtsson wrote:

            
I don't: it is documented to work on a name not an object.

  
    
#
On 4/5/06, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
What comes first, the documentation of a method or the method itself?  ;)

I noticed the last year or so, that the documentation is being
referred to as a requirement/design specification, in addition to
being help pages.  If this is in general true, that is a good
guideline.  Has this evolved recently, or is it just me that missed it
before?

/Henrik
--
Henrik Bengtsson
Mobile: +46 708 909208 (+2h UTC)