为什么 $ 不部分匹配线性模型的摘要?

Why does $ not partially match on summaries of linear models?

summary(lm(wt~mpg,data=mtcars))->aa$r returns NULL,提示没有以r开头的变量名。然而,a$residualsa$r.squared 都给出了有效的输出,与这个前提相矛盾。我对 $ 运算符的误解是什么?我以为它总是部分匹配。

?pmatch中有线索(在?$中顺便引用)。

nomatch: the value to be returned at non-matching or multiply partially matching positions.

pmatch 的情况下,它是 NA_integer_,但在 $ 的情况下,我猜它是 NULL(我真的不想深入研究R源码确认)。

更具体地说,"Indexing by vectors" section of the R language manual 表示

x$aa will match x$aabb if x does not contain a component named "aa" and "aabb" is the only name which has prefix "aa".

它没有明确说明否则会返回 NULL,但这通常是您在没有匹配项时得到的结果(例如 a$junk)。

在更抽象的层面上,当存在多个部分匹配项时,很难想出 unsurprising/principled/non-dangerous 解决歧义的方法:选择第一个按字母顺序排列的(可能因区域设置等而异) ?选择数值指数最低的那个?