R package to convert a raw text version of an individual’s name into a structured format.
The functions work out the order of the name parts (first, middle and last), strip titles, credentials and suffixes, and estimate gender from the given names.
Installation
remotes::install_github("Nonprofit-Open-Data-Collective/peopleparser")
library(peopleparser)Use
parse_names() takes a vector of raw names and returns a data frame with one row per name and these columns:
-
name, the input -
salutation, titles and credentials (DR,MD_PHD,TREASURER) -
first_name,middle_name,last_name -
suffix(JR,III) andstatus(RESIGNED,PAST,ASOF) -
gender(M,ForU) andgender_confidence(50 to 100)
x <- c("Karen H Green", "ED MARKS", "MATTHEW BERSHADKER", "R Blincoe",
"HAFER JR EDMUND L AIA", "Dr Leslie Smith", "THOMAS H VON KAMECKE",
"livingston III, Mr. MICHAEL JOHN9", "JANE DOE RN MA TERM ENDED")
parse_names(x) |> knitr::kable()| name | salutation | first_name | middle_name | last_name | suffix | status | gender | gender_confidence |
|---|---|---|---|---|---|---|---|---|
| Karen H Green | KAREN | H | GREEN | F | 99.8 | |||
| ED MARKS | ED | MARKS | M | 99.4 | ||||
| MATTHEW BERSHADKER | MATTHEW | BERSHADKER | M | 99.9 | ||||
| R Blincoe | R | BLINCOE | U | 50.0 | ||||
| HAFER JR EDMUND L AIA | AIA | EDMUND | L | HAFER | JR | M | 99.9 | |
| Dr Leslie Smith | DR | LESLIE | SMITH | F | 81.8 | |||
| THOMAS H VON KAMECKE | THOMAS | H | VON-KAMECKE | M | 99.9 | |||
| livingston III, Mr. MICHAEL JOHN9 | MR | MICHAEL | JOHN | LIVINGSTON | III | M | 99.8 | |
| JANE DOE RN MA TERM ENDED | RN_MA | JANE | DOE | F | 99.4 |
The name order and gender come from how often each word is a first name or a surname, and how often a first name is given to men or to women, in U.S. Census Bureau name lists (the bundled census.names table, built from the 2020 Census first-name and surname lists).
parse_name() parses a single name. It expects sanitized input, so set sanitize = TRUE for raw text:
parse_name("livingston III, Mr. MICHAEL JOHN9", sanitize = TRUE) |> knitr::kable()| salutation | first_name | middle_name | last_name | suffix | status | gender | gender_confidence |
|---|---|---|---|---|---|---|---|
| MR | MICHAEL | JOHN | LIVINGSTON | III | M | 99.8 |
Nicknames and canonical first names
With add_nicknames = TRUE, each first name also gets its formal names, its type (formal name or nickname) and one canonical first name, so that BOB, ROBERT and ROB can be matched as the same person. Lists of formal names are separated by ;;. A gendered salutation decides names such as PAT (the gender column itself comes from the census counts only):
x <- c("Bob Jones", "MRS PAT LEE", "MR PAT LEE", "Kathy Ruiz", "STEVEN H PARK")
parse_names(x, add_nicknames = TRUE)[
, c("name", "salutation", "first_name", "first_name_type", "first_name_formal",
"first_name_canonical")] |> knitr::kable()| name | salutation | first_name | first_name_type | first_name_formal | first_name_canonical |
|---|---|---|---|---|---|
| Bob Jones | BOB | both | ROBERT | ROBERT | |
| MRS PAT LEE | MRS | PAT | both | PATRICIA;; PATSY | PATRICIA |
| MR PAT LEE | MR | PAT | both | PATRICK | PATRICK |
| Kathy Ruiz | KATHY | nickname | KATHLEEN;; KATHRYN;; KATHERINE;; KATHARINE | KATHY | |
| STEVEN H PARK | STEVEN | formal | STEPHEN |
Organisations, placeholders and run-together names
Officer lists also hold banks, notes and couples. With classify = TRUE, parse_names() adds a name_type column so that they can be set aside before people are matched (classify_names() does this on its own). With split_run_together = TRUE it first splits a surname and given name typed as one word (KramerKenneth, MURPHYSANDRA). Both are off by default.
x <- c("JOHN A SMITH", "PNC BANK NA", "SEE SCHEDULE O",
"MICHAEL AND ASHLEY SMITH", "KramerKenneth", "MURPHYSANDRA")
parse_names(x, classify = TRUE, split_run_together = TRUE)[
, c("name", "first_name", "last_name", "name_type")] |> knitr::kable()| name | first_name | last_name | name_type |
|---|---|---|---|
| JOHN A SMITH | JOHN | SMITH | person |
| PNC BANK NA | PNC | BANK-NA | organisation |
| SEE SCHEDULE O | placeholder | ||
| MICHAEL AND ASHLEY SMITH | MICHAEL | SMITH | several people |
| KramerKenneth | KENNETH | KRAMER | person |
| MURPHYSANDRA | SANDRA | MURPHY | person |
Speed and parallel workers
parse_names() runs in the current R session and starts no background processes unless you ask for them. For large inputs, use workers:
x <- get_example_names(n = 1000)
system.time(pn <- parse_names(x)) # sequential
pn <- parse_names(big_vector, workers = 4) # 4 workers for this call
future::plan(future::multisession, workers = 4) # or reuse workers
a <- parse_names(batch_1) # across calls
b <- parse_names(batch_2)
future::plan(future::sequential)Starting workers takes a few seconds, so they help only on large inputs.
The steps on their own
The parser’s steps are exported, which helps when a name parses in a surprising way:
x <- prep_name("livingston III, Mr. MICHAEL JOHN9") # clean the string
x
#> [1] "LIVINGSTON III MR MICHAEL JOHN"
tokens <- strsplit(x, " ")[[1]]
cd <- get_census_data(tokens) # census counts per word
cd |> knitr::kable()| name | ordinal | male_value | female_value | first_name_value | last_name_value |
|---|---|---|---|---|---|
| LIVINGSTON | 1 | 653 | 102 | 755 | 40605 |
| III | 2 | 0 | 0 | 0 | 0 |
| MR | 3 | 0 | 0 | 0 | 0 |
| MICHAEL | 4 | 3469434 | 7287 | 3476721 | 37760 |
| JOHN | 5 | 3118620 | 6503 | 3125123 | 37363 |
determine_surname(cd) # position of the surname
#> [1] 1Contributors
This package was adapted by Jesse Lecy from Name-Parser by Michael Flanigan (https://github.com/mjfii/Name-Parser).
Versioning
Development began 2020-08-01; version 0.1.0 (2026-11-23) was the first tagged release. See the changelog for each release.