File: test-specialchars.R

package info (click to toggle)
r-cran-bayesfactor 0.9.12-4.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,492 kB
  • sloc: cpp: 1,555; sh: 16; makefile: 7
file content (55 lines) | stat: -rw-r--r-- 1,882 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

context('special chars')

e <- function(x) composeTerm(paste0(x, ' :`"\''))
p <- paste0

data('ToothGrowth')
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
colnames(ToothGrowth) <- paste0(colnames(ToothGrowth), ' :`"\'')

test_that('ttestBF accepts column names with special chars', {
  formula <- p(e('len'), '~', e('supp'))
  formula <- as.formula(formula)
  results <- ttestBF(formula=formula, data=ToothGrowth)
  expect_that(results, is_a("BFBayesFactor"))
  expect_that(length(results), is_equivalent_to(1))
})

test_that('anovaBF accepts column names with special chars', {
  formula <- p(e('len'), '~', e('supp'))
  formula <- as.formula(formula)
  results <- anovaBF(formula=formula, data=ToothGrowth)
  expect_that(results, is_a("BFBayesFactor"))
  expect_that(length(results), is_equivalent_to(1))

  formula <- p(e('len'), '~', e('supp'), '*', e('dose'))
  formula <- as.formula(formula)
  results <- anovaBF(formula=formula, data=ToothGrowth)
  expect_that(results, is_a("BFBayesFactor"))
  expect_that(length(results), is_equivalent_to(4))
})

test_that('generalTestBF accepts column names with special chars', {
  data(puzzles)
  names(puzzles) <- paste0(colnames(puzzles), ' :`"\'')
  formula <- p(e('RT'), '~', e('shape'), '*', e('color'), '*', e('ID'))
  formula <- as.formula(formula)
  bf <- generalTestBF(formula, whichRandom=e('ID'), data = puzzles)
  expect_that(bf, is_a("BFBayesFactor"))
  expect_that(length(bf), is_equivalent_to(18))
})

test_that("regressionBF accepts column names with special chars", {
  set.seed(0)
  x <- rnorm(100)
  a <- rnorm(100)
  y <- x + a + rnorm(100)
  data <- data.frame(y, x, a)
  colnames(data) <- paste0(colnames(data), ' :`"\'')
  formula <- as.formula(p(e('y'), '~', e('x'), '+', e('a')))
  bf <- regressionBF(formula, data)
  expect_that(bf, is_a("BFBayesFactor"))
  expect_that(length(bf), is_equivalent_to(3))
})