R语言如何查看函数源码[例:wilcox.test]
命令
## 查看源码
>stats:::待查看的对象
以wilcox.test为例
## 查看wilcox.test的源码
>stats:::wilcox.test#命令行
function (x, ...)
UseMethod("wilcox.test")
<bytecode: 0x0000024da5b4a4f0>
<environment: namespace:stats>
> stats:::wilcox.test.default#命令行
function (x, y = NULL, alternative = c("two.sided", "less",
"greater"), mu = 0, paired = FALSE, exact = NULL, correct = TRUE,
conf.int = FALSE, conf.level = 0.95, ...)
{
alternative <- match.arg(alternative)
if (!missing(mu) && ((length(mu) > 1L) || !is.finite(mu)))
stop("'mu' must be a single number")
if (conf.int) {
if (!((length(conf.level) == 1L) && is.finite(conf.level) &&
(conf.level > 0) && (conf.level < 1)))
stop("'conf.level' must be a single number between 0 and 1")
}
if (!is.numeric(x))
stop("'x' must be numeric")
if (!is.null(y)) {
if (!is.numeric(y))
stop("'y' must be numeric")
DNAME <- paste(deparse(substitute(x)), "and", deparse(substitute(y)))
if (paired) {
if (length(x) != length(y))
stop("'x' and 'y' must have the same length")
OK <- complete.cases(x, y)
x <- x[OK] - y[OK]
y <- NULL
}
else {
x <- x[is.finite(x)]
y <- y[is.finite(y)]
}
}
else {
DNAME <- deparse(substitute(x))
if (paired)
stop("'y' is missing for paired test")
x <- x[is.finite(x)]
}
if (length(x) < 1L)
stop("not enough (finite) 'x' observations")
CORRECTION <- 0
if (is.null(y)) {
METHOD <- "Wilcoxon signed rank test"
x <- x - mu
ZEROES <- any(x == 0)
if (ZEROES)
x <- x[x != 0]
n <- as.double(length(x))
if (is.null(exact))
exact <- (n < 50)
r <- rank(abs(x))
STATISTIC <- setNames(sum(r[x > 0]), "V")
TIES <- length(r) != length(unique(r))
if (exact && !TIES && !ZEROES) {
PVAL <- switch(alternative, two.sided = {
p <- if (STATISTIC > (n * (n + 1)/4)) psignrank(STATISTIC -
1, n, lower.tail = FALSE) else psignrank(STATISTIC,
n)
min(2 * p, 1)
}, greater = psignrank(STATISTIC - 1, n, lower.tail = FALSE),
less = psignrank(STATISTIC, n))
if (conf.int) {
x <- x + mu
alpha <- 1 - conf.level
diffs <- outer(x, x, "+")
diffs <- sort(diffs[!lower.tri(diffs)])/2
cint <- switch(alternative, two.sided = {
qu <- qsignrank(alpha/2, n)
if (qu == 0) qu <- 1
ql <- n * (n + 1)/2 - qu
achieved.alpha <- 2 * psignrank(trunc(qu) -
1, n)
c(diffs[qu], diffs[ql + 1])
}, greater = {
qu <- qsignrank(alpha, n)
if (qu == 0) qu <- 1