tests/testthat/test-database-operations.R

test_that("lazy database operations retain IDs and column metadata", {
  database <- biogeme_database(
    "operations",
    data.frame(ID = c(1, 1, 2), x = c(1, 2, 3), row.names = c("a", "b", "c"))
  )
  database <- biogeme_database_define_variable(database, "x2", variable("x") * 2)
  database <- biogeme_database_remove(database, variable("x") == 2)

  expect_equal(biogeme_database_row_ids(database), c("a", "b", "c"))
  expect_equal(biogeme_database_columns(database), c("ID", "x", "x2"))
  expect_true(is.na(biogeme_database_filtered_row_count(database)))
  expect_true(is.na(biogeme_database_nrow(database)))
})

test_that("panel declarations enforce contiguous observation blocks", {
  database <- biogeme_panel_database(
    "panel",
    data.frame(ID = c(1, 1, 2, 2), x = 1:4),
    "ID"
  )
  expect_true(biogeme_database_is_panel(database))

  expect_error(
    biogeme_panel_database("bad_panel", data.frame(ID = c(1, 2, 1), x = 1:3), "ID"),
    "contiguously"
  )
})

Try the rbiogeme package in your browser

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

rbiogeme documentation built on Sept. 29, 2026, 5:09 p.m.