tests/testthat/test-rng-state.R

test_that("agg devices do not advance global RNG state on creation", {

  set.seed(123)
  dev <- agg_capture()
  handle <- dev()
  dev.off()
  a1 <- runif(1)
  b1 <- .Random.seed

  set.seed(123)
  a2 <- runif(1)
  b2 <- .Random.seed

  expect_equal(a1, a2)
  expect_equal(b1, b2)
})

test_that("agg_record does not advance global RNG state on creation", {
  # with ragg
  set.seed(456)
  agg_record()
  dev.off()
  a1 <- runif(1)
  b1 <- .Random.seed

  set.seed(456)
  a2 <- runif(1)
  b2 <- .Random.seed

  expect_equal(a1, a2)
  expect_equal(b1, b2)
})

Try the ragg package in your browser

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

ragg documentation built on March 23, 2026, 9:06 a.m.