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
See source code for survplot function in Design package
6 messages · Eleni Rapsomaniki, Frank E Harrell Jr, Marc Schwartz +2 more
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
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 Eleni
The 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.Design
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:
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090205/2cb455bd/attachment-0001.pl>
Marc Schwartz <marc_schwartz <at> comcast.net> writes:
getAnywhere("function.method")
Which also works without the ""
getAnywhere(xtabs)
getAnywhere("xtabs")
Dieter