tests/testthat/test_get_private.R

test_that("get_private<- works", {
  a = R6Class("A",
    private = list(
      y = 123
    )
  )$new()

  get_private(a, "y") = 314L
  expect_true(get_private(a)$y == 314L)
})

test_that("get_private<- checks for correct input", {
  a = R6Class("A",
    private = list(
      y = 123
    )
  )$new()

  expect_error({
    get_private(a, c("x", "y")) = 314L
  })
  expect_error({
    get_private(a, character(0)) = 314L
  })
  expect_error({
    get_private(a, NULL) = 314L
  })
})

Try the mlr3misc package in your browser

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

mlr3misc documentation built on Sept. 20, 2023, 5:06 p.m.