【发布时间】:2014-09-13 15:46:26
【问题描述】:
在R中,为什么data和formula关键字的顺序在绘图时很重要?我认为对于 命名参数,顺序 不 应该很重要......
有关我的意思的示例,请查看以下代码:
library(MASS)
data(menarche)
# Correct formulation (apparently):
plot(formula=Menarche/Total ~ Age, data=menarche)
# In contrast, note how the following returns an error:
plot(data=menarche, formula=Menarche/Total ~ Age)
这只是 plot 函数的一个怪癖,还是其他函数也有这种行为?
【问题讨论】:
-
graphics:::plot.default(data=menarche, formula=Menarche/Total ~ Age)与graphics:::plot.formula(data=menarche, formula=Menarche/Total ~ Age) -
@rawr 对;是 S3 分派处理参数并分派到不同的方法,而不是导致错误的顺序。但是,第一个应该是
graphics:::plot.data.frame,因为traceback()表明实际调用的是这个方法。