tests/testthat/test-loop_execution.R

# loops - correlation ---------------------------------------------------------

test_that(
  desc = "bf_corr_test works in loop",
  code = {
    skip_on_cran()

    col.name <- colnames(mtcars)

    set.seed(123)
    ls <-
      capture.output(for (i in 4:5) {
        print(bf_corr_test(
          data = mtcars,
          x = disp,
          y = col.name[i]
        ))
      })

    expect_true(length(ls) >= 6L)
  }
)

# loops - contingency tabs ---------------------------------------------------

test_that(
  desc = "bf_contingency_tab works in loop",
  code = {
    skip_on_cran()

    df <- dplyr::select(mtcars, am, cyl, vs)
    col.name <- colnames(df)

    set.seed(123)
    ls <-
      capture.output(for (i in 1:3) {
        print(bf_contingency_tab(
          data = mtcars,
          x = col.name[i]
        ))
      })

    expect_true(length(ls) >= 10L)
  }
)

# loops - bf_ttest ---------------------------------------------------

test_that(
  desc = "bf_ttest works in loop",
  code = {
    skip_on_cran()

    # working with loops
    df <- dplyr::select(mtcars, am, wt, mpg)
    col.name <- colnames(df)

    set.seed(123)
    ls1 <-
      capture.output(for (i in 2:length(col.name)) {
        print(bf_ttest(
          data = mtcars,
          x = am,
          y = !!col.name[i]
        ))
      })

    expect_true(length(ls1) >= 8L)

    set.seed(123)
    ls2 <-
      capture.output(for (i in 2:length(col.name)) {
        print(bf_ttest(
          data = mtcars,
          x = col.name[i],
          test.value = 3
        ))
      })

    expect_true(length(ls2) >= 8L)
  }
)

# loops - bf_anova ---------------------------------------------------

test_that(
  desc = "bf_anova works in loop",
  code = {
    skip_on_cran()

    # working with loops
    df <- dplyr::select(mtcars, cyl, wt, mpg)
    col.name <- colnames(df)

    set.seed(123)
    ls <-
      capture.output(for (i in 2:length(col.name)) {
        print(bf_oneway_anova(
          data = mtcars,
          x = cyl,
          y = !!col.name[i]
        ))
      })

    expect_true(length(ls) >= 22L)
  }
)

Try the tidyBF package in your browser

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

tidyBF documentation built on June 12, 2021, 9:06 a.m.