File: test-aes.r

package info (click to toggle)
r-cran-ggplot2 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,412 kB
  • sloc: sh: 9; makefile: 1
file content (62 lines) | stat: -rw-r--r-- 2,755 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
context("Creating aesthetic mappings")

test_that("function aes", {
  expect_equal(aes(x = mpg, y = wt),
               structure(list(x = bquote(mpg), y = bquote(wt)), class = "uneval"))

  expect_equal(aes(x = mpg ^ 2, y = wt / cyl),
               structure(list(x = bquote(mpg ^ 2), y = bquote(wt / cyl)), class = "uneval"))

})

test_that("function aes_string", {
  expect_equal(aes_string(x = "mpg", y = "wt"),
               structure(list(x = bquote(mpg), y = bquote(wt)), class = "uneval"))

  expect_equal(aes_string(x = "mpg ^ 2", y = "wt / cyl"),
               structure(list(x = bquote(mpg ^ 2), y = bquote(wt / cyl)), class = "uneval"))
})

test_that("function aes_all", {
  expect_equal(aes_all(names(mtcars)),
               structure(
                 list(
                   mpg = bquote(mpg),
                   cyl = bquote(cyl),
                   disp = bquote(disp),
                   hp = bquote(hp),
                   drat = bquote(drat),
                   wt = bquote(wt),
                   qsec = bquote(qsec),
                   vs = bquote(vs),
                   am = bquote(am),
                   gear = bquote(gear),
                   carb = bquote(carb)),
                 class = "uneval"))

  expect_equal(aes_all(c("x", "y", "col", "pch")),
               structure(list(x = bquote(x), y = bquote(y), colour = bquote(col), shape = bquote(pch)), class = "uneval"))
})

test_that("function aes_auto", {
  df <- data.frame(x = 1, y = 1, colour = 1, label = 1, pch = 1)
  expect_equal(aes_auto(df),
               structure(list(colour = bquote(colour), label = bquote(label), shape = bquote(pch), x = bquote(x), y = bquote(y)), class = "uneval"))

  expect_equal(aes_auto(names(df)),
               structure(list(colour = bquote(colour), label = bquote(label), shape = bquote(pch), x = bquote(x), y = bquote(y)), class = "uneval"))

  df <- data.frame(xp = 1:3, y = 1:3, colour = 1:3, txt = letters[1:3], foo = 1:3)
  expect_equal(aes_auto(df, x = xp, label = txt),
               structure(list(colour = bquote(colour), y = bquote(y), x = bquote(xp), label = bquote(txt)), class = "uneval"))
  expect_equal(aes_auto(names(df), x = xp, label = txt),
               structure(list(colour = bquote(colour), y = bquote(y), x = bquote(xp), label = bquote(txt)), class = "uneval"))
  expect_equal(aes_auto(x = xp, label = txt, data = df),
               structure(list(colour = bquote(colour), y = bquote(y), x = bquote(xp), label = bquote(txt)), class = "uneval"))

  df <- data.frame(foo = 1:3)
  expect_equal(aes_auto(df, x = xp, y = yp),
               structure(list(x = bquote(xp), y = bquote(yp)), class = "uneval"))
  expect_equal(aes_auto(df), structure(setNames(list(), character(0)), class = "uneval"))
})