tests/testthat/test-insertRowAndKeepAttr.R

library("testthat")
context("insertRowAndKeepAttr")

test_that("Keeps attributes", {
  test <- matrix(1:4, ncol = 2)
  attr(test, "wow") <- 1000
  test <- insertRowAndKeepAttr(test, 1)

  expect_equal(attr(test, "wow"), 1000)
  expect_equal(nrow(test), 3)
})

test_that("Keeps class", {
  test <- matrix(1:4, ncol = 2)
  attr(test, "wow") <- 1000
  class(test) <- c("new_class", class(test))
  test <- insertRowAndKeepAttr(test, 1)

  expect_true("new_class" %in% class(test)[1])
})

Try the Gmisc package in your browser

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

Gmisc documentation built on Aug. 26, 2023, 1:07 a.m.