Search posts, tags, users, and pages
Is there a reason you prefer to use a new.env() rather than a list (which is how I would have done it)?
Great question, and good to hear from you! Lists and environments are extremely similar (thanks to the functional, Scheme-like nature of R) so either should be possible. If I get a chance, I'll see how much difference appears when written with lists.
IMO environments are a slightly better match for hash tables because they are exactly hashed in their implementation and unordered (whereas lists have sequential elements) and they work by reference (instead of copying on change, thus can be performance enhancing). I'm not sure whether there are different scale issues vs. lists, but wouldn't expect any (because of the underlying Scheme-like nature, as above).
Still, the old joke about economists applies to most things in R: if you ask a question of 4 R experts, you'll get 5 different answers :)
Looking to see if anyone has compared these, I found that Jeffrey Horner has: jeffreyhorner.tumblr.com/post/114524915928/hash-t…
The takeaway from that is that environments (using their default behavior of being hash tables under the hood) are substantially more efficient.
Environments/hashes have nearly constant speed (close to O(1)) as the size grows, but lists take linearly increasing time (close to O(n)) for lookups.