I have looked this question and this question, but neither seems to address the problem of checking for the existence of an integer key in a list.
Consider the following example.
mylist=list()
mylist[[5]] = 1
# How do I programmatically check whether 5 is a key for this list?
5 %in% names(mylist) # returns FALSE, because names(mylist) is NULL here.
Update: Clarification, using another language, like Python. Here is the behavior I am trying to replicate in R
.
foo = {}
foo[5] = 1
if 5 in foo: # How do I say "if 5 in foo" in R?
print foo[5]
# Do other stuff