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

Commit

Permalink
Remove dependency on the pacta package
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolepore committed Dec 4, 2019
1 parent 72a7c42 commit 7a8c576
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 26 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ Imports:
tidyr
Suggests:
covr,
pacta (>= 0.0.0.9000),
r2dii.dataraw (>= 0.0.2.9000),
testthat (>= 2.1.0)
Remotes:
2DegreesInvesting/pacta,
2degreesinvesting/r2dii.dataraw,
2degreesinvesting/r2dii.utils
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion R/replace_customer_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' `to`.
#'
#' @examples
#' library(tibble)
#' library(dplyr)
#'
#' replace_customer_name("A. and B")
#' replace_customer_name("Acuity Brands Inc")
Expand Down
2 changes: 1 addition & 1 deletion man/replace_customer_name.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-match_all_against_all.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library(tibble)
library(dplyr)

test_that("match_all_against_all outputs a tibble", {
x <- tibble(sector = "A", simpler_name = "a")
Expand Down
148 changes: 127 additions & 21 deletions tests/testthat/test-replace_customer_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,48 +104,154 @@ test_that("replace_customer_name with custom ownership types works ok", {
)
})

test_that("replace_customer_name errors with malformed `from_to`", {
expect_error(
replace_customer_name("a", from_to = tibble(bad = "a", to = "b")),
"must have all expected names"
)

expect_error(
replace_customer_name("a", from_to = tibble(from = "a", bad = "b")),
"must have all expected names"
)
})

test_that("get_replacements outputs the expectes tibble", {
expect_is(get_replacements(), "tbl_df")
expect_named(get_replacements(), c("from", "to"))
})

# pacta_data_name_reductions ----------------------------------------------
# datapasta::tribble_paste(pacta::data.name.reductions)
pacta_data_name_reductions <- dplyr::tribble(
~From, ~To,
" and ", " & ",
" och ", " & ",
" en ", " & ",
" und ", " & ",
"(pte)", "",
"(pvt)", "",
"(pjsc)", "",
"development", "dev",
"group", "grp",
"financing", "fing",
"financial", "fina",
"finance", "fine",
"designated activity company", "dac",
"limited partnership", "lp",
"generation", "gen",
"investment", "invest",
"limited", "ltd",
"company", "co",
"public ltd co", "plc",
"public co ltd", "pcl",
"corporation", "corp",
"ltd liability co", "llc",
"aktg", "ag",
"incorporated", "inc",
"holdings", "hldgs",
"holding", "hldgs",
"international", "intl",
"government", "govt",
"berhad", "bhd",
"golden", "gld",
"resources", "res",
"resource", "res",
"shipping", "shp",
"partners", "prt",
"partner", "prt",
"associates", "assoc",
"associate", "assoc",
"groep", "grp",
"generation", "gen",
"investment", "invest",
"financial", "fin",
"spolka z ", "sp z ",
"ograniczona odpowiedzialnoscia", "oo",
"sp z oo", "spzoo",
"sp z o o", "spzoo",
"sanayi ve ticaret", "sanayi ticaret",
"sanayi", "san",
"ticaret", "tic",
"sirketi", "sti",
"san tic ltd sti", "santicltdsti",
"san tic anonim sti", "santicanonimsti",
"1", "one",
"2", "two",
"3", "three",
"4", "four",
"5", "five",
"6", "six",
"7", "seven",
"8", "eight",
"9", "nine",
"0", "null"
)

test_that("get_replacements() is equal to its legacy in pacta", {
expect_equal(
setdiff(get_replacements()$from, pacta::data.name.reductions$From),
setdiff(get_replacements()$from, pacta_data_name_reductions$From),
character(0)
)

expect_equal(
setdiff(pacta::data.name.reductions$From, get_replacements()$from),
setdiff(pacta_data_name_reductions$From, get_replacements()$from),
character(0)
)

expect_equal(
setdiff(get_replacements()$to, pacta::data.name.reductions$To),
setdiff(get_replacements()$to, pacta_data_name_reductions$To),
character(0)
)

expect_equal(
setdiff(pacta::data.name.reductions$To, get_replacements()$to),
setdiff(pacta_data_name_reductions$To, get_replacements()$to),
character(0)
)
})

# pacta_data_ownership_types ----------------------------------------------
# datapasta::dpasta(pacta_data_ownership_types)
pacta_data_ownership_types <- c(
"dac",
"sas",
"asa",
"spa",
"pte",
"srl",
"ltd",
"plc",
"pcl",
"bsc",
"sarl",
"as",
"nv",
"bv",
"cv",
"pt",
"sa",
"se",
"lp",
"corp",
"co",
"llc",
"ag",
"ab",
"inc",
"hldgs",
"intl",
"govt",
"bhd",
"jsc",
"pjsc",
"gmbh",
"spzoo"
)

test_that("get_ownership_type() is equal to its legacy in pacta", {
expect_equal(
setdiff(get_ownership_type(), pacta::data.ownership.types),
setdiff(get_ownership_type(), pacta_data_ownership_types),
character(0)
)
})

test_that("replace_customer_name errors with malformed `from_to`", {
expect_error(
replace_customer_name("a", from_to = tibble(bad = "a", to = "b")),
"must have all expected names"
)

expect_error(
replace_customer_name("a", from_to = tibble(from = "a", bad = "b")),
"must have all expected names"
)
})

test_that("get_replacements outputs the expectes tibble", {
expect_is(get_replacements(), "tbl_df")
expect_named(get_replacements(), c("from", "to"))
})

0 comments on commit 7a8c576

Please sign in to comment.