File: test-data.r

package info (click to toggle)
r-cran-ggplot2 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,184 kB
  • sloc: sh: 15; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 969 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
context("Data")

test_that("stringsAsFactors doesn't affect results", {
    old <- getOption("stringsAsFactors")
    on.exit(options(stringsAsFactors = old), add = TRUE)

    dat.character <- data_frame(x = letters[5:1], y = 1:5, stringsAsFactors = FALSE)
    dat.factor <- data_frame(x = letters[5:1], y = 1:5, stringsAsFactors = TRUE)

    base <- ggplot(mapping = aes(x, y)) + geom_point()
    xlabels <- function(x) x$layout$panel_params[[1]]$x$get_labels()

    options(stringsAsFactors = TRUE)
    char_true <- ggplot_build(base %+% dat.character)
    factor_true <- ggplot_build(base %+% dat.factor)

    options(stringsAsFactors = FALSE)
    char_false <- ggplot_build(base %+% dat.character)
    factor_false <- ggplot_build(base %+% dat.factor)

    expect_equal(xlabels(char_true), letters[1:5])
    expect_equal(xlabels(char_false), letters[1:5])
    expect_equal(xlabels(factor_true), letters[1:5])
    expect_equal(xlabels(factor_false), letters[1:5])
})