File: test-replace_nan_inf.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-- 798 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
test_that("extract from data frame", {
  x <- c(1, 2, NA, 3, NaN, 4, NA, 5, Inf, -Inf, 6, 7)

  expect_identical(
    replace_nan_inf(x),
    c(1, 2, NA, 3, NA, 4, NA, 5, NA, NA, 6, 7)
  )

  # a data frame
  df <- data.frame(
    x = c(1, NA, 5, Inf, 2, NA),
    y = c(3, NaN, 4, -Inf, 6, 7),
    stringsAsFactors = FALSE
  )

  expect_identical(
    replace_nan_inf(df),
    structure(
      list(
        x = c(1, NA, 5, NA, 2, NA),
        y = c(3, NA, 4, NA, 6, 7)
      ),
      row.names = c(NA, -6L),
      class = "data.frame"
    )
  )

  expect_identical(
    replace_nan_inf(df, select = starts_with("x")),
    structure(
      list(
        x = c(1, NA, 5, NA, 2, NA),
        y = c(3, NaN, 4, -Inf, 6, 7)
      ),
      row.names = c(NA, -6L),
      class = "data.frame"
    )
  )
})