tests/testthat/test-selecting_variables.R

# select specific variables for correlation -----------------------------

test_that("selecting specific variables works", {
  skip_if_not_or_load_if_installed("poorman")
  set.seed(123)
  df1 <- mtcars %>%
    correlation(
      select = c("cyl", "wt"),
      select2 = "hp"
    )

  set.seed(123)
  df2 <- mtcars %>%
    group_by(am) %>%
    correlation(
      select = c("cyl", "wt"),
      select2 = "hp"
    )

  set.seed(123)
  df3 <- mtcars %>%
    correlation(select = "wt", select2 = "hp")

  set.seed(123)
  df4 <- mtcars %>%
    correlation(select = c("wt", "hp"))

  expect_snapshot(list(df1, df2, df3, df4))

  expect_equal(df3$r, df4$r, tolerance = 0.001)
  expect_equal(df3$t, df4$t, tolerance = 0.001)
})

Try the correlation package in your browser

Any scripts or data that you put into this service are public.

correlation documentation built on April 6, 2023, 5:18 p.m.