Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option allows reserved loanbook columns #328

Merged
merged 5 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/match_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ match_name_impl <- function(loanbook,
old_groups <- dplyr::groups(loanbook)
loanbook <- ungroup(loanbook)

abort_reserved_column(loanbook)
if (!allow_reserved_columns()) abort_reserved_column(loanbook)
loanbook_rowid <- tibble::rowid_to_column(loanbook)

prep_lbk <- restructure_loanbook(loanbook_rowid, overwrite = overwrite)
Expand Down Expand Up @@ -159,6 +159,10 @@ match_name_impl <- function(loanbook,
matched
}

allow_reserved_columns <- function() {
isTRUE(getOption("r2dii.match.allow_reserved_columns"))
}

abort_reserved_column <- function(data) {
reserved_chr <- c("alias", "rowid", "sector")
is_reserved <- names(data) %in% reserved_chr
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-match_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -587,3 +587,15 @@ test_that("matches any case of ald$name_company, but preserves original case", {
# The original uppercase is preserved
expect_equal(upp$name_ald, "ALPINE KNITS")
})

test_that("with relevant options allows loanbook with reserved columns", {
restore <- options(r2dii.match.allow_reserved_columns = TRUE)
on.exit(options(restore), add = TRUE)

# Must add both `sector` and `borderline` -- match_name errors with just one
lbk <- mutate(fake_lbk(), sector = "a", borderline = FALSE)
expect_no_error(
# Don't warn if found no match
suppressWarnings(match_name(lbk, fake_ald()))
)
})