Skip to content
Prev 276684 / 398506 Next

Unexpected behavior when browsing list objects by name, when the object name is a substring (prefix) of an existing object that has a valid value

You've stumbled on one of the reasons use of the $ operator is
discouraged in formal programming: it uses partial matching when given
names.

E.g.,

a = list(boy = 1:5, cat = 1:10, dog = 1:3)

a$d #Exists

If you want to require exact matching (and it seems you do), use the
[[ operator.

a[["d"]] # Error
a[["dog"]] # Works
a[["alligator"]] <- 1:100  #Works

Michael
On Tue, Nov 8, 2011 at 12:29 AM, Val Athaide <vathaid at gmail.com> wrote: