File: test-verb-pull.R

package info (click to toggle)
r-cran-dbplyr 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,376 kB
  • sloc: sh: 13; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 823 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
test_that("can extract default, by name, or positive/negative position", {
  x <- 1:10
  y <- runif(10)
  mf <- memdb_frame(x = x, y = y)

  expect_equal(pull(mf), y)
  expect_equal(pull(mf, x), x)
  expect_equal(pull(mf, 1L), x)
  expect_equal(pull(mf, -1), y)
})

test_that("extracts correct column from grouped tbl", {
  mf <- memdb_frame(id = "a", value = 42)
  gf <- mf %>% group_by(id)

  expect_equal(pull(mf, value), 42)
})

test_that("doesn't unnecessarily select", {
  mf <- memdb_frame(x = c(3, 1, 2))
  # no warning about select after arrange
  expect_warning(out <- mf %>% arrange(x) %>% pull(), NA)
  expect_equal(out, 1:3)
})

test_that("ungroup() produces nice error messages", {
  expect_snapshot(error = TRUE, {
    memdb_frame(x = 1) %>% pull(non_existent)
    memdb_frame(x = 1) %>% pull(1000)
  })
})