Skip to content

Commit

Permalink
catch expected warnings in join_coalesce() test (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb authored Aug 7, 2023
1 parent 487c1a2 commit f68c359
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/testthat/test-utils_join_coalesce.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ test_that("join coalesce function works", {
x <- data.frame(id1 = c(NA_character_,letters[1:4]), a = c(1,NA,3,NA,5), b = 1:5 * 10)
y <- data.frame(id2 = c(letters[3:11],NA_character_), a = -(1:10), c = 1:10 * 100)

left1 <- join_coalesce(x,y, by = c("id1"="id2"))
left2 <- join_coalesce(x,y, by.x = "id1", by.y = "id2")
inner1 <- join_coalesce(x,y, by = c("id1"="id2"), type = "inner")
full1 <- join_coalesce(x,y, by = c("id1"="id2"), type = "full")
# Keys include NAs and trigger a warning
expect_warning(
left1 <- join_coalesce(x, y, by = c("id1" = "id2"))
)
expect_warning(
left2 <- join_coalesce(x, y, by.x = "id1", by.y = "id2")
)
expect_warning(
inner1 <- join_coalesce(x, y, by = c("id1" = "id2"), type = "inner")
)
expect_warning(
full1 <- join_coalesce(x, y, by = c("id1" = "id2"), type = "full")
)

expect_equal(left1,left2) # both join-by methods work the same
expect_equal(sum(is.na(left1$a)), 1) # one NA on left join
Expand Down

0 comments on commit f68c359

Please sign in to comment.