Eleni Rapsomaniki
2009-Feb-05 16:54 UTC
[R] See source code for survplot function in Design package
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
Frank E Harrell Jr
2009-Feb-05 18:02 UTC
[R] See source code for survplot function in Design package
Eleni Rapsomaniki wrote:> 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> 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> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
Marc Schwartz
2009-Feb-05 18:03 UTC
[R] See source code for survplot function in Design package
on 02/05/2009 10:54 AM Eleni Rapsomaniki wrote:> 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 > EleniThe easiest way is probably to use getAnywhere(): library(Design)> getAnywhere("survplot")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:> methods(survplot)[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:> survplot.Designfunction (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
Dieter Menne
2009-Feb-05 19:10 UTC
[R] See source code for survplot function in Design package
Eleni Rapsomaniki <e.rapsomaniki <at> mail.cryst.bbk.ac.uk> writes:> 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)?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