File: test-data_addprefix.R

package info (click to toggle)
r-cran-datawizard 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,300 kB
  • sloc: sh: 13; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download | duplicates (2)
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
test_that("data_addprefix works as expected", {
  expect_equal(
    names(head(data_addprefix(iris, "NEW_"))),
    c(
      "NEW_Sepal.Length", "NEW_Sepal.Width", "NEW_Petal.Length",
      "NEW_Petal.Width", "NEW_Species"
    )
  )

  expect_equal(
    names(head(data_addsuffix(iris, "_OLD"))),
    c(
      "Sepal.Length_OLD", "Sepal.Width_OLD", "Petal.Length_OLD",
      "Petal.Width_OLD", "Species_OLD"
    )
  )

  expect_equal(
    names(head(data_addprefix(iris, "NEW_", select = starts_with("Sepal")))),
    c("NEW_Sepal.Length", "NEW_Sepal.Width", "Petal.Length", "Petal.Width", "Species")
  )

  expect_equal(
    names(head(data_addsuffix(iris, "_OLD", select = starts_with("Petal")))),
    c("Sepal.Length", "Sepal.Width", "Petal.Length_OLD", "Petal.Width_OLD", "Species")
  )
})

# select helpers ------------------------------
test_that("data_addprefix regex", {
  expect_equal(
    data_addsuffix(mtcars, "_regex", select = "pg", regex = TRUE),
    data_addsuffix(mtcars, "_regex", select = "mpg")
  )
  expect_equal(
    data_addsuffix(mtcars, select = "pg$", "_regex", regex = TRUE),
    data_addsuffix(mtcars, select = "mpg", "_regex")
  )
})