test_df <- data.frame(
matrix(ncol=100,nrow=100,rnorm(1000)),
col = letters[round(runif(1:100, min = 1,max = 5))],
col1 = letters[round(runif(1:100, min = 15,max = 20))]
)
testthat::test_that(
"convert_age does what expected",
{
test_df_dummy <- c("col", "col1") %>%
purrr::map(~dummy_vars(test_df, variable = .x)) %>%
bind_cols %>%
bind_cols(test_df, .)
testthat::expect_identical(
ncol(test_df_dummy),
ncol(test_df) + length((unique(test_df$col))) + length((unique(test_df$col1)))
)
## Unique rows from dummy of col should be the same as number of factors in col
testthat::expect_identical(
length(unique(test_df_dummy[,letters[1:5]])),
length(unique(test_df[["col"]]))
)
## Should only be possible for one class to be 1 at a time
testthat::expect_identical(
unname(colSums(unique(test_df_dummy[,letters[1:5]]))),
rep(1, length(unique(test_df[["col"]])))
)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.