context("Test utilitaries")
test_that("join_frames works as expected", {
require(tibble)
df1 <- data.frame(a = c(1, 2), b = c("x1", "z1"))
df2 <- data.frame(a = c(1, 2), c = c("x2", "z2"))
df3 <- data.frame(a = c(1, 2, 1, 2), d = c("x3", "z3", "x4", "z4"))
expect_equal(
join_frames(df1, df2, df3, id_names = "a"),
structure(list(a = c(1, 1, 2, 2), b = structure(c(1L, 1L, 2L, 2L), .Label = c("x1", "z1"), class = "factor"), c = structure(c(1L, 1L, 2L, 2L), .Label = c("x2", "z2"), class = "factor"), d = structure(1:4, .Label = c("x3", "x4", "z3", "z4"), class = "factor")), row.names = c(NA, -4L), class = "data.frame") #nolint
)
expect_warning(join_frames(df1, df1, id_names = "a"))
df4 <- data.frame(a = c(3), e = c("x5"))
expect_equal(
join_frames(df1, df4, id_names = "a"),
structure(list(a = c(1, 2), b = structure(1:2, .Label = c("x1", "z1"), class = "factor"), e = structure(c(NA_integer_, NA_integer_), .Label = "x5", class = "factor")), row.names = c(NA, -2L), class = "data.frame") #nolint
)
expect_equal(
join_frames(df1, id_names = "a"),
df1
)
expect_error(
join_frames(df1, df2, id_names = "b")
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.