-
Notifications
You must be signed in to change notification settings - Fork 8
Description
@kevinushey pointed out (in Bug 18353) that using $ on a hashtab (as returned by the hashtab() function) object silently fails and $<- on one not only doesn't work, but permanently corrupts the object:
> ht <- hashtab()
> ht[["mykey"]] <- "hi"
> ht
<hashtable 0x1214aa070: count = 1, type = "identical">
> ht[["mykey"]]
[1] "hi"
> ht$mykey
NULL
> ht
<hashtable 0x1214aa070: count = 1, type = "identical">
> ht$mykey2 <- "oh noes"
> ht
Error in numhash(x) : not a proper hash table object
<snip>
> ht[["mykey"]]
Error in gethash(h, key, nomatch) : not a proper hash table object
<snip>
At the very least I'd argue that the corruption is an actual bug(let), but I'd suggest fixing both.
One possibility is allow hashtab objects to support the $ interface, while the more conservative approach would be to make at least $<- and preferably (in my mind) also $ simply throw an error that in the former case protects the integrity of the object.
I suggest creating both patches (at first blush it looks like they should be extremely similar) and let R-core choose which to apply.
Remember to update the documentation and add regression tests for whichever case(s) you implement in your patch(es).