Skip to contents

Returns a copy of data with flagged columns removed or their values replaced. Four methods, in increasing order of what survives:

Usage

pii_redact(
  data,
  findings = pii_scan(data),
  method = "placeholder",
  key = NULL,
  min_confidence = NULL
)

Arguments

data

A data frame.

findings

The result of pii_scan() on data. Scanned if missing.

method

One method for every flagged column, or a named vector giving the method per finding type, with an optional default.

key

A secret string that determines the pseudonyms; needed only for "pseudonym". Keep it out of the shared files; use the same key to redact files that must still join.

min_confidence

The weakest findings to act on; the configuration's min_confidence, or "medium", unless given.

Value

data with the flagged columns redacted, and the actions taken as its "redactions" attribute: the column name, the type acted on, the method, and left, the flagged types left in a column where only matches were replaced.

Details

  • "drop" removes the column.

  • "placeholder", the default, replaces each value with its type, such as <EMAIL>.

  • "mask" keeps the first two characters and hides the rest.

  • "pseudonym" replaces each value with a made-up one of the same shape, the same every time for the same value and key, so joins across files, counts of distinct people and format checks still work.

In free text, and in any column where only some values match, only the matched email addresses, phone numbers and IP addresses are replaced, every one of them; with "drop" the whole column goes. Anything else flagged in such a column, such as a name inside an answer, is left in place.

Fields allowed in the project's configuration (see pii_config()) are left alone, as pii_check() leaves them alone.

Pseudonyms are drawn from SHA-256 of the key and the value, so they are the same in every session; they take about a second per 7,000 distinct values. Different values of the same shape can collide: for n values of a shape with S possible spellings, about n^2 / 2S pairs do.

Pseudonyms are for keeping analyses running, not for security. They are not encryption, and a column of pseudonyms can still identify people through what surrounds it. Anyone who knows the key can test whether a guessed value, such as a phone number, gives a pseudonym in the file, so the key has no default and must not be shared with the data.

Examples

survey <- data.frame(
  id = 1:20,
  email = paste0("person", 1:20, "@example.org"),
  village = rep(c("Palpur", "Netrad"), 10)
)
clean <- pii_redact(survey, method = c(email = "pseudonym", default = "drop"), key = "s3")
head(clean)
#>   id               email
#> 1  1 grufwb9@wmfxars.wuv
#> 2  2 lliqur6@mieytmk.bse
#> 3  3 lhqjro8@pfspxjo.cru
#> 4  4 tplqui3@tvghwid.fvg
#> 5  5 vfxdwo8@mddrtid.ypk
#> 6  6 ofzjgw1@onwqfqd.pyx
attr(clean, "redactions")
#> # A tibble: 2 × 4
#>   name    type     method    left 
#>   <chr>   <chr>    <chr>     <chr>
#> 1 email   email    pseudonym ""   
#> 2 village location drop      ""