File: test-qplot.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 (39 lines) | stat: -rw-r--r-- 925 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
context("qplot")

test_that("qplot works with variables in data frame and parent env", {
  df <- data_frame(x = 1:10, a = 1:10)
  y <- 1:10
  b <- 1:10

  expect_is(qplot(x, y, data = df), "ggplot")
  expect_is(qplot(x, y, data = df, colour = a), "ggplot")
  expect_is(qplot(x, y, data = df, colour = b), "ggplot")

  bin <- 1
  expect_is(qplot(x, data = df, binwidth = bin), "ggplot")
})

test_that("qplot works in non-standard environments", {
  p <- local({
    `-1-` <- 10
    x <- 1:10
    qplot(x, breaks = 0:`-1-`)
  })
  expect_is(p, "ggplot")
})

test_that("qplot() evaluates constants in the right place", {
  p <- local({
    foo <- "d"
    qplot(1, 1, colour = I(paste0("re", foo)))
  })
  expect_identical(layer_data(p)$colour, I("red"))
})

test_that("qplot() evaluates layers in package environment", {
  geom_line <- function(...) {
    stop("!!!")
  }

  expect_error(p <- qplot(1, 1, geom = "line"), NA)
})