tests/testthat/test-s7-S7_S3_class.R

test_that("S7_S3_class", {
  expect_snapshot({
    # example from `?S7::new_S3_class`

    S3_Date <- S7::new_S3_class(
      "Date",
      function(.data = integer()) {
        .Date(.data)
      },
      function(self) {
        if (!is.numeric(self)) {
          "Underlying data must be numeric"
        }
      }
    )
    # avoid changing environment address issue
    environment(S3_Date$validator) <- .GlobalEnv
    environment(S3_Date$constructor) <- .GlobalEnv
    construct(S3_Date)
  })
})

Try the constructive package in your browser

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

constructive documentation built on Nov. 5, 2025, 7:14 p.m.