knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

pinr

Travis build status Coverage status

The goal of pinr is to simplify working with data containing Finnish personal identity codes (PINs). You can:

Installation

Currently you can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("mikmart/pinr")

Usage

The primary (pipe-friendly) utility function automates pseudonymizing columns containing PINs in your data:

library(pinr)

df <- data.frame(pin = c("311280-888Y", "311280-888Y", "131052-308T"))
key <- data.frame(pin = c("311280-888Y", "131052-308T"), pid = c(1, 2))

pseudonymize(df, key, pid = pin)

The result is equivalent to looking up the pid from the key data frame, but pinr also takes care of managing the columns and naming in your data.

key$pid[match(df$pin, key$pin)]

Rather than manually specifying columns containing PINs, you can also use a heuristic implemented in the is_probably_pin() function to guess which columns need to be pseudonymized:

pseudonymize(df, key, guess = TRUE, replace = FALSE)

pinr also includes helpers for extracting data contained in the Finnish PINs, such as the date of birth and sex:

pins <- c("311280-888Y", "131052-308T")

pin_dob(pins)

pin_sex(pins)

There is also a pin_extract() wrapper for these extraction functions that makes it easy to extract these data into new columns in a data frame context:

pin_extract(df, pin)

All of the pinr functions that work with data frames are pipe-friendly, lending themselves to readable workflows such as this:

library(magrittr) # for the pipe operator

df %>% 
  pin_extract(pin) %>% 
  pseudonymize(key, pid = pin)


fbc-studies/pinr documentation built on May 17, 2019, 7:35 p.m.