Why doesn't R allow $ operator on atomic vectors?

The following will display the error "Error in v $ a: $ operator is not valid for atomic vectors" (at least in version R.1.1.1.1):

v <- c(a='a',b='b') v$a 

Apparently, R had previously admitted this, which makes me curious why.

EDIT: As indicated below, v$a would return NULL in earlier versions. Changed “quite recently” to “earlier” since I based it on old internet forums and was fixed below.

+6
source share
2 answers

I believe the reason is that using v$a vs. v[['a']] is considered less secure.

EDIT: More on this LINK .

+7
source

The third paragraph of the "Details" section ?"$" :

'$ is valid only for recursive objects and is considered only in the below on recursive objects. Its use on non-recursive objects was deprecated in R 2.5.0 and removed in R 2.7.0.

R-2.7.0 was released in April 2008. Four years are far from being “recent,” but perhaps for a while you had several versions?

+6
source

Source: https://habr.com/ru/post/911412/


All Articles