Nothing
options(stringsAsFactors = FALSE)
test_that('empty data.frames work', {
expect_identical(repr_html(data.frame()), '')
expect_identical(repr_html(as.data.frame(matrix(integer(0L), 1L, 0L))), '')
# no data.frame without colnames possible
})
test_that('empty matrices work', {
expect_identical(repr_html(matrix(integer(0L), 0L, 0L)), '')
expect_identical(repr_html(matrix(integer(0L), 1L, 0L)), '')
expect_identical(repr_html(matrix(integer(0L), 0L, 1L)), '')
})
test_that('factors display correctly', {
df = data.frame(a = factor('iamafactor'))
expect_identical(repr_html(df),
'<table class="dataframe">
<caption>A data.frame: 1 \u00D7 1</caption>
<thead>
\t<tr><th scope=col>a</th></tr>
\t<tr><th scope=col><fct></th></tr>
</thead>
<tbody>
\t<tr><td>iamafactor</td></tr>
</tbody>
</table>
')
})
test_that('mixed factors and strings display correctly', {
df = data.frame(a = 'iamastring', b = factor('iamafactor'))
expect_true(is.factor(df$b))
expect_identical(repr_html(df),
'<table class="dataframe">
<caption>A data.frame: 1 \u00D7 2</caption>
<thead>
\t<tr><th scope=col>a</th><th scope=col>b</th></tr>
\t<tr><th scope=col><chr></th><th scope=col><fct></th></tr>
</thead>
<tbody>
\t<tr><td>iamastring</td><td>iamafactor</td></tr>
</tbody>
</table>
')
})
test_that('date display correctly', {
df = data.frame(a = as.POSIXct('2016-05-28 10:00:00', tz = 'UTC'))
expect_identical(repr_html(df),
'<table class="dataframe">
<caption>A data.frame: 1 \u00D7 1</caption>
<thead>
\t<tr><th scope=col>a</th></tr>
\t<tr><th scope=col><dttm></th></tr>
</thead>
<tbody>
\t<tr><td>2016-05-28 10:00:00</td></tr>
</tbody>
</table>
')
})
test_that('markdown works', {
df <- data.frame(a = 1:2, b = letters[1:2])
expect_identical(repr_markdown(df), '
A data.frame: 2 \u00D7 2
| a <int> | b <chr> |
|---|---|
| 1 | a |
| 2 | b |
')
})
test_that('markdown works with rownames', {
df <- data.frame(a = 1:2, b = letters[1:2], row.names = LETTERS[1:2])
expect_identical(repr_markdown(df), '
A data.frame: 2 \u00D7 2
| <!--/--> | a <int> | b <chr> |
|---|---|---|
| A | 1 | a |
| B | 2 | b |
')
})
test_that('latex works', {
df <- data.frame(a = 1:2, b = letters[1:2])
expected <-
'A data.frame: 2 \u00D7 2
\\begin{tabular}{ll}
a & b\\\\
<int> & <chr>\\\\
\\hline
\t 1 & a\\\\
\t 2 & b\\\\
\\end{tabular}
'
expect_identical(repr_latex(df), expected)
})
test_that('latex works with rownames', {
df <- data.frame(a = 1:2, b = letters[1:2], row.names = LETTERS[1:2])
expected <-
'A data.frame: 2 \u00D7 2
\\begin{tabular}{r|ll}
& a & b\\\\
& <int> & <chr>\\\\
\\hline
\tA & 1 & a\\\\
\tB & 2 & b\\\\
\\end{tabular}
'
expect_identical(repr_latex(df), expected)
})
test_that('nested data.frames work', {
df <- data.frame(driver = c('Bowser', 'Peach'))
df$vehicle <- data.frame(model = c('Piranha Prowler', 'Royal Racer'))
df$vehicle$stats <- data.frame(speed = c(55, 34), weight = c(67, 24), drift = c(35, 32))
df$occupation <- c('Koopa', 'Princess')
expect_identical(repr_markdown(df), '
A data.frame: 2 \u00D7 6
| driver <chr> | vehicle.model <chr> | vehicle.stats.speed <dbl> | vehicle.stats.weight <dbl> | vehicle.stats.drift <dbl> | occupation <chr> |
|---|---|---|---|---|---|
| Bowser | Piranha Prowler | 55 | 67 | 35 | Koopa |
| Peach | Royal Racer | 34 | 24 | 32 | Princess |
')
})
test_that('matrices in data.frames work', {
df <- aggregate(. ~ Species, iris, range)
expect_equal(dim(df$Sepal.Width), c(3, 2))
expect_identical(repr_markdown(df), '
A data.frame: 3 \u00D7 5
| Species <fct> | Sepal.Length <dbl[,2]> | Sepal.Width <dbl[,2]> | Petal.Length <dbl[,2]> | Petal.Width <dbl[,2]> |
|---|---|---|---|---|
| setosa | 4.3, 5.8 | 2.3, 4.4 | 1.0, 1.9 | 0.1, 0.6 |
| versicolor | 4.9, 7.0 | 2.0, 3.4 | 3.0, 5.1 | 1.0, 1.8 |
| virginica | 4.9, 7.9 | 2.2, 3.8 | 4.5, 6.9 | 1.4, 2.5 |
')
})
test_that('reprs work on an 1d array', {
state <- factor(c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa", "qld", "vic"))
incomes <- c(60, 49, 40, 61, 64, 60, 59, 54, 62, 69)
one_d_arr <- tapply(incomes, state, mean)
repr_html(one_d_arr)
repr_latex(one_d_arr)
repr_markdown(one_d_arr)
succeed()
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.