inst/tinytest/test_par.R

if (at_home()) {
  # Plot =======================================================================
  ## Capture and cleanup plot output
  path <- file.path(tempdir(), "Rplot.pdf")
  on.exit(unlink(path))
  pdf(file = path)

  ## Save graphical parameters
  old_par <- graphics::par(no.readonly = TRUE)

  ## Plot...
  ternary_plot(NULL)

  ## ...changes the user's graphical parameters...
  new_par <- graphics::par(no.readonly = TRUE)
  # expect_identical(new_par, old_par) # Fails

  dev.off()

  ## ...but these are the dimensions of the plotting region
  ## (so it should be OK?)
  keys <- new_par[!(new_par %in% old_par)]
  expect_identical(names(keys), c('pin', 'plt', 'usr', 'yaxp'))

  # Pairs ======================================================================
  ## Capture and cleanup plot output
  path <- file.path(tempdir(), "Rplot.pdf")
  on.exit(unlink(path))
  pdf(file = path)

  ## Save graphical parameters
  old_par <- graphics::par(no.readonly = TRUE)

  ## Plot...
  ternary_pairs(lava)

  ## ...does not change the user's graphical parameters
  new_par <- graphics::par(no.readonly = TRUE)
  expect_identical(new_par, old_par)

  dev.off()
}

Try the isopleuros package in your browser

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

isopleuros documentation built on April 3, 2025, 7:40 p.m.