# how to run this test:
# devtools::test(filter="prcomp")
context("test prcomp functions")
test_that("do_prcomp", {
df <- mtcars %>% mutate(new_col = c(rep("A", n() - 10), rep("B", 10)))
model_df <- do_prcomp(df, cyl, mpg, hp, max_nrow=30)
model_df %>% tidy_rowwise(model, type="variances")
model_df %>% tidy_rowwise(model, type="loadings")
model_df %>% tidy_rowwise(model, type="biplot")
model_df %>% tidy_rowwise(model, type="screeplot")
res <- model_df %>% tidy_rowwise(model, type="data")
expect_equal(colnames(res),
c("mpg","cyl","disp","hp","drat","wt","qsec","vs","am","gear","carb","new_col","PC1","PC2","PC3"))
})
test_that("do_prcomp with strange column name", {
df <- mtcars %>%
rename(`Cy l` = cyl) %>%
mutate(new_col = c(rep("A", n() - 10), rep("B", 10)))
model_df <- do_prcomp(df, `Cy l`, mpg, hp)
model_df %>% tidy_rowwise(model, type="variances")
model_df %>% tidy_rowwise(model, type="loadings")
model_df %>% tidy_rowwise(model, type="biplot")
model_df %>% tidy_rowwise(model, type="screeplot")
res <- model_df %>% tidy_rowwise(model, type="data")
expect_equal(colnames(res),
c("mpg","Cy l","disp","hp","drat","wt","qsec","vs","am","gear","carb","new_col","PC1","PC2","PC3"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.