An R package for generating pseudonyms that are delightful and easy to remember. It creates adorable anonymous animals like the Likeable Leech and the Proud Chikadee.
OTHER License
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
set.seed(122020)
noah (no animals were harmed) generates pseudonyms that are delightful and easy to remember. It creates adorable anonymous animals like the Likable Leech and the Proud Chickadee.
Install from CRAN with:
install.packages("noah")
Or install the development version from Github with:
# install.packages("remotes")
remotes::install_github("teebusch/noah")
Use pseudonymize()
to generate a unique pseudonym for every unique element / row in a vector or data frame. pseudonymize()
accepts multiple vectors and data frames as arguments, and will pseudonymize them row by row.
library(noah)
pseudonymize(1:9)
pseudonymize(
c("🐰", "🐰", "🐰"),
c("🥕", "🥕", "🍰")
)
For extra delight, we can ask noah to generate only alliterations:
pseudonymize(1:9, .alliterate = TRUE)
You can use pseudonymize()
with dplyr::mutate()
to add a column with pseudonyms to a data frame. In this example we use the diabetic retinopathy dataset from the package survival
and add a new column with a pseudonym for each unique id. We also use dplyr::relocate()
to move the pseudonyms to the first column:
library(dplyr)
diabetic <- as_tibble(survival::diabetic)
diabetic %>%
mutate(pseudonym = pseudonymize(id)) %>%
relocate(pseudonym)
For your convenience, noah also provides add_pseudonyms()
, which wraps mutate()
and relocate()
and supports tidyselect syntax for selecting the key columns:
diabetic %>%
add_pseudonyms(id, where(is.factor))
To make sure that all pseudonyms are unique and consistent, pseudonymize()
and add_pseudonyms()
use an object of class Ark
(a pseudonym archive). By default, a new Ark
is created for each function call, but you can also provide an Ark
yourself. This allows you to keep track of the pseudonyms that have been used and make sure that the same keys always get assigned the same pseudonym:
ark <- Ark$new()
# split dataset into left and right eye and pseudonymize separately
diabetic_left <- diabetic %>%
filter(eye == "left") %>%
add_pseudonyms(id, .ark = ark)
diabetic_right <- diabetic %>%
filter(eye == "right") %>%
add_pseudonyms(id, .ark = ark)
# reunite the data sets again
bind_rows(diabetic_left, diabetic_right) %>%
arrange(id)
The ark now contains r length(ark)
pseudonyms -- as many as there are unique id's in the dataset.
length(unique(diabetic$id))
length(ark)
Building your own Ark allows you to customize the name parts that are used to create pseudonyms (by default, adjectives and animals). It also allow you to use names with more than two parts:
ark <- Ark$new(parts = list(
c("Charles", "Louis", "Henry", "George"),
c("I", "II", "III", "IV"),
c("The Good", "The Wise", "The Brave", "The Mad", "The Beloved")
))
pseudonymize(1:8, .ark = ark)
You can also configure an Ark
so that it generates only alliterations. Note that this behavior can still be overridden temporarily by using .alliterate = FALSE
when you call pseudonymize()
.
ark <- Ark$new(alliterate = TRUE)
pseudonymize(1:12, .ark = ark)
Noah will treat numerically identical whole numbers of type double
and integer
as different and give them different pseudonyms. This can cause some unexpected behavior. Consider this example:
ark <- Ark$new()
pseudonymize(1:2, .ark = ark) # creates a vector of integers c(1L, 2L)
pseudonymize(1, .ark = ark) # creates a double
You might expect to get 2 different pseudonyms, because in the second pseudonymize()
you are requesting a pseudonym for the number 1
, which is already in the Ark. Instead you get three pseudonyms:
length(ark)
Noah will warn you when it thinks you are making this mistake, but it might not catch it all the time. A workaround is to coerce types explicitly, for example by using as.double()
, as.integer()
, or 1L
to create integers.
There are multiple R packages that generate fake data, including fake names, phone numbers, addresses, credit card numbers, gene sequences and more:
If you need watertight anonymization you should check out these packages for anonymizing personal identifiable information in data sets: