Skip to content

See source code for survplot function in Design package

6 messages · Eleni Rapsomaniki, Frank E Harrell Jr, Marc Schwartz +2 more

#
Dear R users,

I know one way to see the code for a hidden function, say function_x,  
is using default.function_x (e.g. summary.default). But how can I see  
the code for imported packages that have no namespace (in this case  
Design)?

Many Thanks
Eleni
#
Eleni Rapsomaniki wrote:
> methods(survplot)
[1] survplot.Design
[2] survplot.residuals.psm.censored.normalized
[3] survplot.survfit

Type any one of those function names to see the full code.  Or go to 
http://biostat.mc.vanderbilt.edu/cgi-bin/viewvc.cgi/Design/trunk/ as 
detailed in the home page for Design: 
http://biostat.mc.vanderbilt.edu/s/Design

Frank

  
    
#
on 02/05/2009 10:54 AM Eleni Rapsomaniki wrote:
The easiest way is probably to use getAnywhere():

library(Design)
A single object matching ?survplot? was found
It was found in the following places
  package:Design
with value

function (fit, ...)
UseMethod("survplot")


This tells you that the function is in package Design and has certain
dispatch methods associated with it. There is also the absence of any
indication of a namespace being present.

The next step would be:
[1] survplot.Design
[2] survplot.residuals.psm.censored.normalized
[3] survplot.survfit

which tells you which methods are present for the function. Note also
that there is no 'default' method.

Note that the methods for survplot() are not hidden within a namespace,
as they would normally be followed by a '*' in the output of methods().
Had this been the case, you could use:

  Design:::survplot.Design


Thus, you can just use:
function (fit, ..., xlim, ylim = if (loglog) c(-5, 1.5) else if (what ==
    "survival" & missing(fun)) c(0, 1), xlab, ylab, time.inc,
    what = c("survival", "hazard"), type = c("tsiatis", "kaplan-meier"),
    conf.type = c("log-log", "log", "plain", "none"), conf.int = FALSE,
    conf = c("bars", "bands"), add = FALSE, label.curves = TRUE,
    abbrev.label = FALSE, lty, lwd = par("lwd"), col = 1, adj.subtitle,
    loglog = FALSE, fun, n.risk = FALSE, logt = FALSE, dots = FALSE,
    dotsize = 0.003, grid = FALSE, srt.n.risk = 0, sep.n.risk = 0.056,
    adj.n.risk = 1, y.n.risk, cex.n.risk = 0.6, pr = FALSE)
{
    what <- match.arg(what)
    if (.R.)
        ylim <- ylim
    type <- match.arg(type)
    conf.type <- match.arg(conf.type)
    conf <- match.arg(conf)
    psmfit <- inherits(fit, "psm") || (length(fit$fitFunction) &&
        any(fit$fitFunction == "psm"))
    if (what == "hazard" && !psmfit)
        stop("what=\"hazard\" may only be used for fits from psm")
    if (what == "hazard" & conf.int > 0) {
        warning("conf.int may only be used with what=\"survival\"")
        conf.int <- FALSE
    }
...


and the same for the other methods for the function.

In general, for methods that are within a namespace, you can use:

  namespace:::function.method

or:

  getAnywhere("function.method")


See ?getAnywhere and ?methods

HTH,

Marc Schwartz
#
Eleni Rapsomaniki <e.rapsomaniki <at> mail.cryst.bbk.ac.uk> writes:
Just type the name without ()

library(Design)
Surv


For namespaces, you might also try 

getAnywhere(myfunctioname)

But note that what you see is the bare-bones codes, not the source.
To see comments, for example, better download the code from CRAN,
e.g. from:

http://cran.at.r-project.org/web/packages/abind/index.html


Dieter
#
Marc Schwartz <marc_schwartz <at> comcast.net> writes:
Which also works without the ""

getAnywhere(xtabs)
getAnywhere("xtabs")

Dieter