context('Test that add_margins works properly')
test_that('add_margins works properly', {
df <- data.frame(a = 'text', b = 1:5, c = 1:5, d = 'text',
stringsAsFactors = FALSE)
expect_error(df %>% add_margins())
df %<>% dplyr::select(-d)
added <- df %>% add_margins()
expect_equal(as.numeric(added$Total), c(2 * 1:5, sum(2 * 1:5)))
expect_equal(as.character(tail(added, 1)), c('Total', '15', '15', '30'))
added <- df %>% add_margins(rowsum = FALSE)
expect_false('Total' %in% names(added))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.