tests/testthat/test.identify_variables.r

context("identify_variables")

library(magrittr)
library(tibble)
library(testthat)

rm(list = ls())
set.seed(0)
numcol <- 1:10 %>% as.numeric()
intcol <- numcol %>% as.integer()
chrcol <- c("q", "w", "e", "r", "t", "y", "u", "i", "o", "p")
faccol <- chrcol %>% as.factor()

#### parameters invalid on its face ####

# bad df
expect_error(
  NULL %>%
    identify_variables(),
  "data %>% is.data.frame()",
  fixed = T)

#### normal analysis ####

# normal identify
actual <-
  data.frame(
    a = numcol,
    b = intcol,
    c = chrcol,
    d = faccol,
    stringsAsFactors = F) %>%
  identify_variables()
expected <-
  tibble(
    name = c("a", "b", "c", "d"),
    class = c("numeric", "integer", "character", "factor"),
    type = c("continuous", "continuous", NA, "categorical"))
expect_equal(actual, expected)
markanewman/mndredge documentation built on May 9, 2019, 5:52 a.m.