tests/testthat/test-edit-formula.R

test_that("edit formula", {
  form <- "y ~ A:(x1+x2)"
  edited <- .edit.formula(form, response_col="y", treat_col="A")
  expect_equal(edited[[1]], "response ~ treat:(x1 + x2)")
  expect_equal(edited[[2]], c("x1", "x2"))
})

test_that("edit formula", {
  form <- "y ~ A*(x1+x2)"
  edited <- .edit.formula(form, response_col="y", treat_col="A")
  expect_equal(edited[[1]], "response ~ treat * (x1 + x2)")
  expect_equal(edited[[2]], c("x1", "x2"))
})

test_that("edit formula with odd covariates 1", {
  form <- "y ~ A + y1"
  edited <- .edit.formula(form, response_col="y", treat_col="A")
  expect_equal(edited[[1]], "response ~ treat + y1")
  expect_equal(edited[[2]], c("y1"))
})

test_that("edit formula with odd covariates 2", {
  form <- "y ~ A + A1"
  edited <- .edit.formula(form, response_col="y", treat_col="A")
  expect_equal(edited[[1]], "response ~ treat + A1")
  expect_equal(edited[[2]], c("A1"))
})

Try the RobinCar package in your browser

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

RobinCar documentation built on May 29, 2024, 3:03 a.m.