【发布时间】:2013-07-13 02:06:12
【问题描述】:
有时,使用某些参数调用函数会导致错误消息formal argument "foo" matched by multiple actual arguments。是否可以打印模棱两可的实际参数列表?
我问这个问题的原因目前是plot 类对象的mixEM 函数存在问题(由normalmixEM 从mixtools 包生成)。它不接受产生上述错误的参数ylim,但是当我尝试使用ylim2(它适用于xlab2、main2、col2 等的方式)时,它说"ylim2" is not a graphical parameter .所以我想知道ylim匹配的实际参数是什么?
使用formals(plot.mixEM) 没有帮助,因为它不包含以ylim 开头的任何内容,但最后它引用...,这是传递给plot 的图形参数。但是,对于 plot 函数,ylim 将是明确的。从 R 获取更准确的错误描述以及冲突参数列表会很有帮助。
UPD:MWE:
library(mixtools)
wait = faithful$waiting
mixmdl = normalmixEM(wait)
plot(mixmdl, which = 2, xlim = c(25, 110), nclass=20)
lines(density(wait), lty = 2, lwd = 2)
这会产生错误:
plot(mixmdl, which = 2, xlim = c(25, 110), ylim = c(0, .5), nclass=20)
# Error in hist.default(x, prob = TRUE, main = main2, xlab = xlab2, ylim = c(0, :
# formal argument "ylim" matched by multiple actual arguments`
这根本行不通:
plot(mixmdl, which = 2, xlim = c(25, 110), ylim2 = c(0, .5), nclass=20)
# Warning messages:
# 1: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
# "ylim2" is not a graphical parameter
# 2: In axis(1, ...) : "ylim2" is not a graphical parameter
# 3: In axis(2, ...) : "ylim2" is not a graphical parameter
【问题讨论】:
-
添加产生错误的代码比叙述方式更容易...
-
@agstudy 我添加了一个 MWE。但是,我也希望就如何处理此类错误提供一般性建议,因为这不是我第一次也可能不是最后一次遇到此类问题。
-
仅供参考 - 如果您不小心将参数添加到函数调用两次,也会发生此错误。