Two lists of sample names often describe the same samples, e.g. the names in a lab report and in a field protocol, but they are written differently and in a different order. identifix finds the matching pairs and tells you which names could not be matched safely.
The package contains 99 name pairs with typical differences. In the file, the names of a row belong together (apart from a few that are different on purpose); we shuffle the second column to make it realistic.
ex <- read.csv(system.file("extdata", "sample_names.csv", package = "identifix"),
stringsAsFactors = FALSE, fileEncoding = "UTF-8")
set.seed(1)
lab <- ex$n1
field <- sample(ex$n2)
head(data.frame(lab, field), 10)
#> lab field
#> 1 Sample_Alpha_01 Std_10ng
#> 2 Sample_Alpha_02 Patient_Scrn_AB
#> 3 Sample_Alpha_03 Sample_Alpha_01
#> 4 Sample_Alpha_04 DNA_Sample_002
#> 5 Sample_Alpha_05 Metab_Prof_2
#> 6 Protein_Extract_A Lvr_Tiss_03
#> 7 Protein_Extract_B Wildtype_Mouse_2
#> 8 Protein_Extract_C HeLa_Cells
#> 9 Serum_Reference_X Replicate_B_R2
#> 10 Serum_Reference_Y Buffer_Tris_7.0m <- idfix_match(lab, field)
m
#> <idfix_match> 85 of 99 names in n1 matched (n2 has 99 names)
#> by step: exact 26, case 1, punctuation 6, reorder 6, typo 2, abbreviation 33, date_context 11
#> unmatched: 14 in n1, 14 in n2 -> see idfix_report(x, unmatched_only = TRUE)
#> Positions in n2 for each name in n1:
#> [1] 3 42 88 99 97 38 15 93 77 83 57 70 60 7 85 71 58 44 79 28 12 45 52 39 34
#> [26] 84 NA 29 65 87 91 40 22 4 23 59 18 27 2 32 94 26 6 21 43 75 62 63 54 55
#> [51] NA NA 95 13 67 80 66 89 9 NA NA 51 76 NA NA 61 53 1 33 24 69 30 16 14 37
#> [76] NA NA 86 17 73 96 NA NA NA 11 25 5 74 78 36 46 19 41 82 98 NA NA 35 50The result is an integer vector: for each name of lab
the position of the matching name in field, or
NA. So field[m] is aligned with
lab:
head(data.frame(lab, field = field[m]), 12)
#> lab field
#> 1 Sample_Alpha_01 Sample_Alpha_01
#> 2 Sample_Alpha_02 Sample_Alpha_02
#> 3 Sample_Alpha_03 Sample_Alpha_03
#> 4 Sample_Alpha_04 Sample_Alpha_04
#> 5 Sample_Alpha_05 Sample_Alpha_05
#> 6 Protein_Extract_A protein_extract_a
#> 7 Protein_Extract_B PROTEINEXTRACTB
#> 8 Protein_Extract_C Protein_Extract_C
#> 9 Serum_Reference_X Serum_Ref_X
#> 10 Serum_Reference_Y Serum_Ref_Y
#> 11 Control_Group_01 controlgroup01
#> 12 Control_Group_02 Control Group 02idfix_report() shows which step found each pair. For
names without a match, it explains why and suggests the most similar
unmatched name of the other set. suggestion_check warns if
numbers or dates of the suggestion differ.
rep <- idfix_report(m)
head(rep[!is.na(rep$n2_index), c("n1", "n2", "step")], 15)
#> n1 n2 step
#> 1 Sample_Alpha_01 Sample_Alpha_01 exact
#> 2 Sample_Alpha_02 Sample_Alpha_02 exact
#> 3 Sample_Alpha_03 Sample_Alpha_03 exact
#> 4 Sample_Alpha_04 Sample_Alpha_04 exact
#> 5 Sample_Alpha_05 Sample_Alpha_05 exact
#> 6 Protein_Extract_A protein_extract_a case
#> 7 Protein_Extract_B PROTEINEXTRACTB punctuation
#> 8 Protein_Extract_C Protein_Extract_C exact
#> 9 Serum_Reference_X Serum_Ref_X abbreviation
#> 10 Serum_Reference_Y Serum_Ref_Y abbreviation
#> 11 Control_Group_01 controlgroup01 punctuation
#> 12 Control_Group_02 Control Group 02 punctuation
#> 13 Wildtype_Mouse_1 Wildtype_Mouse_1 exact
#> 14 Wildtype_Mouse_2 Wildtype_Mouse_2 exact
#> 15 Mutant_Mouse_3 Mutant_Mouse_3 exact
idfix_report(m, unmatched_only = TRUE)[, c("n1", "n2", "note", "suggestion_name",
"suggestion_check")]
#> n1 n2 note
#> 1 Exp_2026-11-12_FR <NA> no safe candidate found
#> 2 Buffer_Tris_pH7 <NA> no safe candidate found
#> 3 Buffer_PBS_pH7 <NA> no safe candidate found
#> 4 Centrifuge_Run_1 <NA> no safe candidate found
#> 5 Centrifuge_Run_2 <NA> no safe candidate found
#> 6 Incubation_37C <NA> no safe candidate found
#> 7 Incubation_4C <NA> no safe candidate found
#> 8 Yeast_Culture_01 <NA> no safe candidate found
#> 9 Yeast_Culture_02 <NA> no safe candidate found
#> 10 HeLa_Cell_Line <NA> no safe candidate found
#> 11 HEK293_Cell_Line <NA> no safe candidate found
#> 12 CHO_Cell_Line <NA> no safe candidate found
#> 13 Unmatched_N1_A <NA> no safe candidate found
#> 14 Unmatched_N1_B <NA> no safe candidate found
#> 15 <NA> HeLa_Cells no safe candidate found
#> 16 <NA> Buffer_Tris_7.0 no safe candidate found
#> 17 <NA> Unmatched_N2_Z no safe candidate found
#> 18 <NA> HEK293_Cells no safe candidate found
#> 19 <NA> CHO_Cells no safe candidate found
#> 20 <NA> Unmatched_N2_Y no safe candidate found
#> 21 <NA> Incubation_37_Deg no safe candidate found
#> 22 <NA> Incubation_4_Deg no safe candidate found
#> 23 <NA> Yeast_01 no safe candidate found
#> 24 <NA> Yeast_02 no safe candidate found
#> 25 <NA> Buffer_PBS_7.4 no safe candidate found
#> 26 <NA> Centrifuge_1 no safe candidate found
#> 27 <NA> Centrifuge_2 no safe candidate found
#> 28 <NA> 12/11/2026_Exp no safe candidate found
#> suggestion_name suggestion_check
#> 1 12/11/2026_Exp numbers/dates differ
#> 2 Buffer_Tris_7.0 numbers/dates differ
#> 3 Buffer_PBS_7.4 numbers/dates differ
#> 4 Centrifuge_1 <NA>
#> 5 Centrifuge_2 <NA>
#> 6 Incubation_37_Deg <NA>
#> 7 Incubation_4_Deg <NA>
#> 8 <NA> <NA>
#> 9 <NA> <NA>
#> 10 HeLa_Cells <NA>
#> 11 HEK293_Cells <NA>
#> 12 CHO_Cells <NA>
#> 13 Unmatched_N2_Z numbers/dates differ
#> 14 Unmatched_N2_Z numbers/dates differ
#> 15 HeLa_Cell_Line <NA>
#> 16 Buffer_Tris_pH7 numbers/dates differ
#> 17 Unmatched_N1_A numbers/dates differ
#> 18 HEK293_Cell_Line <NA>
#> 19 CHO_Cell_Line <NA>
#> 20 Unmatched_N1_A numbers/dates differ
#> 21 Incubation_37C <NA>
#> 22 Incubation_4C <NA>
#> 23 <NA> <NA>
#> 24 <NA> <NA>
#> 25 Buffer_PBS_pH7 numbers/dates differ
#> 26 Centrifuge_Run_1 <NA>
#> 27 Centrifuge_Run_2 <NA>
#> 28 Exp_2026-11-12_FR numbers/dates differSome names were not matched on purpose:
Buffer_Tris_pH7 and Buffer_Tris_7.0: the
numbers differ (7 vs. 7.0).Incubation_37C and Incubation_37_Deg:
C and Deg are different words.Exp_2026-11-12_FR and 12/11/2026_Exp: the
other names in field that use / are written
month first (05/22/2026), so 12/11/2026 is
read as 11 December.Centrifuge_Run_1 and Centrifuge_1: a word
is missing. This is only matched by the optional "subset"
step.idfix_steps() lists all steps in the order in which they
run:
idfix_steps()
#> step default confidence
#> 1 exact TRUE high
#> 2 whitespace TRUE high
#> 3 case TRUE high
#> 4 punctuation TRUE high
#> 5 zeros TRUE high
#> 6 dates TRUE medium
#> 7 reorder TRUE medium
#> 8 typo TRUE low
#> 9 abbreviation TRUE low
#> 10 date_context TRUE medium
#> 11 subset FALSE low
#> description
#> 1 identical strings
#> 2 identical after removing all kinds of whitespace
#> 3 identical ignoring upper/lower case
#> 4 identical ignoring separators, punctuation and accents (Français = Francais)
#> 5 identical ignoring leading zeros in numbers (S_01 = S_1)
#> 6 identical after converting dates to one format (2026-09-01 = 1. Sept 2026)
#> 7 same parts in a different order (R1_A = A_R1); numbers keep their order
#> 8 small typos in words (Smaple = Sample); numbers must be identical
#> 9 abbreviated words or acronyms (Std = Standard, QC = Quality_Check)
#> 10 same full date; additional words only on one side (Exp_2026-05-20_EN = 20.05.2026_Exp)
#> 11 all words of one name contained in the other, same numbers (Centrifuge_1 = Centrifuge_Run_1)Pass the steps you want to steps. For example, add the
optional "subset" step:
steps <- c(idfix_steps()$step[idfix_steps()$default], "subset")
m2 <- idfix_match(lab, field, steps = steps)
m2
#> <idfix_match> 89 of 99 names in n1 matched (n2 has 99 names)
#> by step: exact 26, case 1, punctuation 6, reorder 6, typo 2, abbreviation 33, date_context 11, subset 4
#> unmatched: 10 in n1, 10 in n2 -> see idfix_report(x, unmatched_only = TRUE)
#> Positions in n2 for each name in n1:
#> [1] 3 42 88 99 97 38 15 93 77 83 57 70 60 7 85 71 58 44 79 28 12 45 52 39 34
#> [26] 84 NA 29 65 87 91 40 22 4 23 59 18 27 2 32 94 26 6 21 43 75 62 63 54 55
#> [51] NA NA 95 13 67 80 66 89 9 81 90 51 76 NA NA 61 53 1 33 24 69 30 16 14 37
#> [76] 64 68 86 17 73 96 NA NA NA 11 25 5 74 78 36 46 19 41 82 98 NA NA 35 50Or switch off typo correction:
m3 <- idfix_match(lab, field, steps = setdiff(steps, c("typo", "subset")))
sum(!is.na(m3))
#> [1] 84Switching off "case", "punctuation",
"zeros" or "dates" also removes these
normalisations from the later steps. Use this if, in your data,
S_01 and S_1 really are different samples.
idfix_extradat() shows how dates in names are
understood:
idfix_extradat(c("Exp_2026-09-01", "2026Setember01", "1er septembre 2026",
"Trial_Sept_2026", "S_04/03/2026", "Probe 03.04."))
#> name date alternative n_dates
#> 1 Exp_2026-09-01 2026-09-01 <NA> 1
#> 2 2026Setember01 2026-09-01 <NA> 1
#> 3 1er septembre 2026 2026-09-01 <NA> 1
#> 4 Trial_Sept_2026 2026-09 <NA> 1
#> 5 S_04/03/2026 2026-03-04 2026-04-03 1
#> 6 Probe 03.04. --04-03 <NA> 1Numeric dates like 04/03/2026 are ambiguous. With
date_order = "auto" the order is taken from unambiguous
dates in the same set with the same separator. Without such evidence,
dates with dots are read day-first, and other dates keep both readings:
they are only matched if exactly one reading fits a name in the other
set. Use date_order = "dmy" or "mdy" if you
know the convention.
You can correct or add matches by assignment.
idfix_report() marks them as "manual" and
warns if a position is used twice.
i <- which(lab == "Centrifuge_Run_1")
m[i] <- which(field == "Centrifuge_1")
idfix_report(m)[i, c("n1", "n2", "step")]
#> n1 n2 step
#> 60 Centrifuge_Run_1 Centrifuge_1 manualTo get a plain integer vector, use as.vector(m).
idfix_review() shows the pairs one by one: in a window
(RStudio viewer or browser) if the shiny package is installed, otherwise
in the console. Differences between the names are highlighted, each pair
is confirmed or rejected with one key, and for names without a match the
most similar names are offered. Pairs you leave undecided keep their
match.
Every step and every pair has a confidence level (see
idfix_steps()): high (only whitespace, case,
punctuation or leading zeros differ), medium (dates, word
order, additional words next to a date) and low (typos,
abbreviations, missing words, ambiguous dates). Pairs confirmed earlier
or set by hand are known. By default all pairs are shown;
choose levels to check only the uncertain ones:
idfix_known() collects all decisions, from the review
and from corrections by hand, as a table. Save it and pass it to
idfix_match() as known next time: confirmed
pairs are matched first (step "known") and are shown as
confirmed, with the date of the confirmation; rejected pairs are never
matched or suggested again. In idfix_review() such pairs
are already marked as confirmed, so only new names have to be checked;
reject a pair to revoke an earlier confirmation. Decisions accumulate
over the runs.
m[which(lab == "Buffer_Tris_pH7")] <- which(field == "Buffer_Tris_7.0")
known <- idfix_known(m)
known
#> n1 n2 decision date
#> 1 Buffer_Tris_pH7 Buffer_Tris_7.0 confirmed 2026-11-05
#> 2 Centrifuge_Run_1 Centrifuge_1 confirmed 2026-11-05m_next <- idfix_match(lab, field, known = known)
idfix_report(m_next)[lab %in% c("Centrifuge_Run_1", "Buffer_Tris_pH7"),
c("n1", "n2", "step", "confidence", "review", "note")]
#> n1 n2 step confidence review
#> 51 Buffer_Tris_pH7 Buffer_Tris_7.0 known known confirmed
#> 60 Centrifuge_Run_1 Centrifuge_1 known known confirmed
#> note
#> 51 confirmed 2026-11-05
#> 60 confirmed 2026-11-05When the matching is right, idfix_rename() brings names
into the spelling of the other set:
head(idfix_rename(m)) # lab names in field spelling
#> [1] "Sample_Alpha_01" "Sample_Alpha_02" "Sample_Alpha_03"
#> [4] "Sample_Alpha_04" "Sample_Alpha_05" "protein_extract_a"
head(idfix_rename(m, to = "n1")) # field names in lab spelling
#> [1] "Standard_10ng" "Patient_Screen_AB" "Sample_Alpha_01"
#> [4] "DNA_Sample_002" "Metabolite_Profile_2" "Liver_Tissue_03"It also renames directly in objects. It finds by itself where the
names are (names of a vector or list, a column, row or column names);
use where if several places fit.
# a named vector with values per lab sample
conc <- setNames(round(runif(3), 2), lab[1:3])
idfix_rename(m, conc)
#> Sample_Alpha_01 Sample_Alpha_02 Sample_Alpha_03
#> 0.68 0.60 0.24
# field results in long format, renamed into lab spelling
res <- data.frame(sample = rep(field[1:2], each = 2), value = 1:4)
idfix_rename(m, res, to = "n1")
#> sample value
#> 1 Standard_10ng 1
#> 2 Standard_10ng 2
#> 3 Patient_Screen_AB 3
#> 4 Patient_Screen_AB 4Names without match are kept (unmatched = "keep") or set
to NA (unmatched = "na").
idfix_multi() matches several sets into one table with
one row per sample. Each further set is matched against the rows found
so far, so samples that are missing in the first set can still be
aligned between the others.
plate <- c("SAMPLE_ALPHA_01", "Protein Extract B", "dna_sample_001",
"Std_20ng", "Extra_Site_1")
t <- idfix_multi(lab = lab, field = field, plate = plate)
#> Warning: The sets have different lengths (lab: 99, field: 99, plate: 5); not
#> all names can be matched.
t[!is.na(t$plate), ]
#> lab field plate
#> 1 Sample_Alpha_01 Sample_Alpha_01 SAMPLE_ALPHA_01
#> 7 Protein_Extract_B PROTEINEXTRACTB Protein Extract B
#> 33 DNA_Sample_001 DNA_Smaple_001 dna_sample_001
#> 69 Standard_20ng Std_20ng Std_20ng
#> 114 <NA> <NA> Extra_Site_1Check single matchings with idfix_report() and rename
one set into the spelling of another with
idfix_rename():
r <- idfix_report(attr(t, "matches")$plate)
r[!is.na(r$n2), c("n1", "n2", "step", "note")]
#> n1 n2 step note
#> 1 Sample_Alpha_01 SAMPLE_ALPHA_01 case
#> 7 Protein_Extract_B Protein Extract B punctuation
#> 33 DNA_Sample_001 dna_sample_001 case
#> 69 Standard_20ng Std_20ng abbreviation
#> 114 <NA> Extra_Site_1 <NA> no safe candidate found
idfix_rename(t, from = "plate")
#> [1] "Sample_Alpha_01" "Protein_Extract_B" "DNA_Sample_001"
#> [4] "Standard_20ng" "Extra_Site_1"
idfix_rename(t, from = "plate", to = "field")
#> [1] "Sample_Alpha_01" " PROTEINEXTRACTB" "DNA_Smaple_001" "Std_20ng"
#> [5] "Extra_Site_1"idfix_rename() uses the table itself, so rows you remove
or correct by hand are taken into account.