dict_exists_key: Check if key is in dictionary

dict_exists_keyR Documentation

Check if key is in dictionary

Description

The reason for using dictionaries in the first place is performance. Although it is correct that you can use named vectors and lists for the task, the issue is that they are becoming quite slow and memory hungry with more data. Yet what many people don't know is that R has indeed an inbuilt dictionary data structure environments with the option hash = TRUE

Usage

dict_exists_key(
  x,
  where = -1,
  envir = if (missing(frame)) as.environment(where) else sys.frame(frame),
  frame,
  mode = "any",
  inherits = TRUE
)

Arguments

x

key (character)

where

= -1

envir

= if (missing(frame)) as.environment(where) else sys.frame(frame)

frame

frame

mode

= "any"

inherits

= TRUE

Details

https://blog.ephorie.de/hash-me-if-you-can

Value

Vector True/False

Author(s)

Florian Wagner florian.wagner@wagnius.ch

Examples

df <- data.frame(key   = c("ch","se","de","it"),
                 value = c(41L,46L,49L,39L))
hash <- dict_from_data.frame(df)
dict_exists_key(c("ch", "it", "xx"), hash)

wagnius-GmbH/slvwagner documentation built on Jan. 19, 2025, 7:10 a.m.