Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Merge bb256bc into 840a1b3
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed Jan 13, 2020
2 parents 840a1b3 + bb256bc commit 19436d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions R/match_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,26 @@ match_name <- function(loanbook,
no_match <- identical(nrow(matched), 0L)
if (no_match) {
warning("Found no match.", call. = FALSE)
return(named_tibble(names = minimum_names_of_match_name(loanbook)))
named_tibble(names = minimum_names_of_match_name(loanbook)) %>%
unsuffix_and_regroup(old_groups) %>%
return()
}

preferred <- prefer_perfect_match_by(matched, .data$id)

out <- preferred %>%
preferred %>%
restore_cols_sector_name_from_ald(prep_ald) %>%
# Restore columns from loanbook
left_join(loanbook_rowid, by = "rowid") %>%
mutate(rowid = NULL) %>%
reorder_names_as_in_loanbook(loanbook_rowid)
reorder_names_as_in_loanbook(loanbook_rowid) %>%
unsuffix_and_regroup(old_groups)
}

dplyr::group_by(out, !!!old_groups)
unsuffix_and_regroup <- function(data, old_groups) {
data %>%
rename(alias = .data$alias_lbk) %>%
dplyr::group_by(!!!old_groups)
}

pick_min_score <- function(data, min_score) {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-match_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ expected_names_of_match_name_with_loanbook_demo <- c(
"sector_ald",
"name",
"name_ald",
"alias_lbk",
"alias",
"alias_ald",
"score",
"source"
Expand Down Expand Up @@ -73,7 +73,7 @@ test_that("match_name w/ row 1 of loanbook and crucial cols yields expected", {
sector_ald = "power",
name = "Alpine Knits India Pvt. Limited",
name_ald = "alpine knits india pvt. limited",
alias_lbk = "alpineknitsindiapvt ltd",
alias = "alpineknitsindiapvt ltd",
alias_ald = "alpineknitsindiapvt ltd",
score = 1,
source = "loanbook"
Expand Down Expand Up @@ -186,7 +186,7 @@ test_that("match_name outputs only perfect matches if any (#40 @2diiKlaus)", {

nanimo_scores <- this_lbk %>%
match_name(ald_demo) %>%
filter(alias_lbk == this_alias) %>%
filter(alias == this_alias) %>%
pull(score)

expect_true(
Expand Down

0 comments on commit 19436d2

Please sign in to comment.