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 26
|
context("Data")
test_that("stringsAsFactors doesn't affect results", {
sAF <- getOption("stringsAsFactors")
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(, aes(x, y)) + geom_point()
xlabels <- function(x) x$panel$ranges[[1]]$x.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)
options(stringsAsFactors = sAF)
expect_that(xlabels(char_true), equals(letters[1:5]))
expect_that(xlabels(char_false), equals(letters[1:5]))
expect_that(xlabels(factor_true), equals(letters[1:5]))
expect_that(xlabels(factor_false), equals(letters[1:5]))
})
|