hash: hash or unhash columns of a tibble

Description Usage Arguments Value Examples

View source: R/hash.R

Description

hash() calculates a simple 6-character hash of each element of a character vector. This can be used for obfuscating sensitive information. hash() is NOT appropriate for de-identification because (a) the algorithm is not cryptographically secure and (b) the hash cannot be easily reversed in a separate R session or without the original values.

unhash() takes a vector of keys and returns their original values. unhash() can only work in the same R session as hash() on the original data.

Usage

1
2
3
hash(values, except = NULL)

unhash(keys)

Arguments

values

character() of values to be hashed.

except

character(1) regular expression of values to be excluded from hashing (appearing in original form in the output).

keys

character() of keys (produced by hash()) to be replaced by their values.

Value

hash() returns a character vector the same length as the input, but with values replaced by their hashed equivalent. Internally, the package stores the hash as a key to be used to look up the value when using unhash().

unhash() returns a character vector the same llength as the input, but with keys replaced by their original values. Elements of key not hashed in the current R session are returned unchanged.

Examples

1
2
3
4
5
month.name
keys <- hash(month.name, except = "^Ma")
keys

unhash(keys)

mtmorgan/mixpanel documentation built on Dec. 21, 2021, 11 p.m.