【问题标题】:Getting arguments of heplot function from heplots R package从 heplots R 包中获取 heplot 函数的参数
【发布时间】:2014-09-18 05:56:19
【问题描述】:

获取R 函数的参数非常简单,可以通过args(functionname) 提取。但我不知道如何从heplots 包中获取heplot 函数的参数。

library(heplots)
?heplot
args(heplot)

function (mod, ...) 
NULL

我想得到以下部分:

## S3 method for class 'mlm'
heplot(mod, terms, hypotheses, term.labels = TRUE,
    hyp.labels = TRUE, err.label="Error", label.pos=NULL,
    variables = 1:2, error.ellipse = !add, 
    factor.means = !add, grand.mean = !add, remove.intercept = TRUE,
    type = c("II", "III", "2", "3"), idata=NULL, idesign=NULL,
    icontrasts=c("contr.sum", "contr.poly"),
    imatrix=NULL, iterm=NULL, markH0=!is.null(iterm),
    manova, size = c("evidence", "effect.size"),
    level = 0.68, alpha = 0.05, segments = 40, 
    center.pch = "+", center.cex=2,
    col = getOption("heplot.colors", 
               c("red", "blue", "black", "darkgreen", 
                 "darkcyan","magenta", "brown","darkgray")),
    lty = 2:1, lwd = 1:2, 
    fill=FALSE, fill.alpha=0.3,   
    xlab, ylab, main = "", xlim, ylim, axes=TRUE, offset.axes, 
    add = FALSE, verbose = FALSE, warn.rank = FALSE, ...)

【问题讨论】:

  • 能否提供一些测试数据?
  • @voidHead - 此数据已完成。该函数是args工作所需的所有数据。
  • 尝试args(heplot.mlm),因为该函数正在调用专门针对mlm类对象的方法
  • @thelatemail:args(heplot.mlm) 中的错误:找不到对象“heplot.mlm”

标签: r statistics multivariate-testing


【解决方案1】:

heplot 是一个 S3 通用函数。它使用了一个方法,heplot.mlm,这是一个非导出函数。您可以通过首先查看heplot 的函数体来访问该信息。如果您在函数体中看到UseMethod,则该函数使用了一个方法。 S3 泛型函数的所有可用方法都可以通过methods 访问

> methods(heplot)

要访问非导出函数,您可以使用:::。用args 包装该调用,您就有了您要查找的参数列表。

> args(heplots:::heplot.mlm)
# function (mod, terms, hypotheses, term.labels = TRUE, hyp.labels = TRUE, 
#     err.label = "Error", label.pos = NULL, variables = 1:2, error.ellipse = !add, 
#     factor.means = !add, grand.mean = !add, remove.intercept = TRUE, 
#     type = c("II", "III", "2", "3"), idata = NULL, idesign = NULL, 
#     icontrasts = c("contr.sum", "contr.poly"), imatrix = NULL, 
#     iterm = NULL, markH0 = !is.null(iterm), manova, size = c("evidence", 
#         "effect.size"), level = 0.68, alpha = 0.05, segments = 40, 
#     center.pch = "+", center.cex = 2, col = getOption("heplot.colors", 
#         c("red", "blue", "black", "darkgreen", "darkcyan", "magenta", 
#             "brown", "darkgray")), lty = 2:1, lwd = 1:2, fill = FALSE, 
#     fill.alpha = 0.3, xlab, ylab, main = "", xlim, ylim, axes = TRUE, 
#     offset.axes, add = FALSE, verbose = FALSE, warn.rank = FALSE, 
#     ...) 
# NULL

注意:这个函数显然有很多参数,所以

> formals(args(heplots:::heplot.mlm))  ## or as.list()

可能是一种更好、更易读的方式来遍历参数列表。

【讨论】:

  • 感谢@Richard 的帮助并提供了很好的解决方案。
猜你喜欢
  • 2021-05-06
  • 1970-01-01
  • 1970-01-01
  • 2022-11-14
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 1970-01-01
  • 2021-04-17
相关资源
最近更新 更多