Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

local_testthat

Unit test helpers


Description

Local helper functions for package unit tests

Usage

local_testthat_assign(x, values, envir = parent.frame())

local_testthat_tolerances(
  tolerances = c(1e-05, 0.01, 0.1),
  envir = parent.frame()
)

local_bru_options_set(..., .reset = FALSE, envir = parent.frame())

local_set_PROJ6_warnings(proj4 = FALSE, thin = TRUE, envir = parent.frame())

local_get_rgdal_options()

local_disable_PROJ6_warnings(envir = parent.frame())

local_basic_intercept_testdata()

local_basic_fixed_effect_testdata()

local_mrsea_convert(x, use_km = FALSE)

local_bru_safe_inla(multicore = FALSE, quietly = TRUE, envir = parent.frame())

local_bru_testthat_setup(envir = parent.frame())

Arguments

x

character; Name of variable to assign to

values

the object to assign to x

envir

environment for exit handlers

tolerances

numeric vector of length 3; [lowtol, midtol, hitol]

.reset

For local_bru_options_set, logical indicating if the global override options list should be emptied before setting the new option(s).

proj4

logical; whether to show PROJ4 conversion warnings. Default FALSE

thin

logical; whether to show only a thinned version of rgdal PROJ6 warnings. Default TRUE

multicore

logical; if TRUE, multiple cores are allowed, and the INLA num.threads option is not checked or altered. Default: FALSE, multicore not allowed (used for examples and unit tests).

quietly

logical; if TRUE, prints diagnostic messages. A message is always printed if the INLA num.threads option is altered, regardless of the quietly argument. Default: TRUE.

Details

local_bru_options_set() is used to set global package options.

Value

local_bru_options_set() returns a copy of the global override options (not including the defaults), invisibly.

Functions

  • local_testthat_assign: Assign local variable. Useful for easy cleanup of global workspace with withr::deferred_run() when running tests interactively.

  • local_testthat_tolerances: Assign test tolerances Assign local tolerance variables. Useful for easy cleanup of global workspace with withr::deferred_run() when running tests interactively.

  • local_bru_options_set: Calls bru_options_set() in a reversible way

  • local_set_PROJ6_warnings: Disable PROJ4/6 warnings. To be used within package tests. Restores state on exit.

  • local_get_rgdal_options: Return a list of the current rgdal warning options

  • local_disable_PROJ6_warnings: Disable rgdal PROJ4 conversion warnings and thin PROJ6 warnings.

  • local_bru_safe_inla: Tests should set num.threads = "1:1" to ensure within-system repeatability by calling local_bru_safe_inla(); see also bru_safe_inla()

  • local_bru_testthat_setup: Initialise environment for tests. Disables PROJ4/PROJ6 warnings, and assigns tolerance variables. To be called either at the top of a testfile, or inside tests. Does not call local_bru_safe_inla(), since that may invoke a skip and should be called inside each test that relies on INLA.

See Also

Examples

my_fun <- function(val) {
  local_bru_options_set(bru_verbose = val)
  bru_options_get("bru_verbose")
}
# Inside the function, the bru_verbose option is changed.
# Outside the function, the bru_verbose option is unchanged.
print(my_fun(TRUE))
print(bru_options_get("bru_verbose"))
print(my_fun(FALSE))
print(bru_options_get("bru_verbose"))

inlabru

Bayesian Latent Gaussian Modelling using INLA and Extensions

v2.3.1
GPL (>= 2)
Authors
Finn Lindgren [aut, cre, cph] (<https://orcid.org/0000-0002-5833-2011>, Finn Lindgren continued development of the main code), Fabian E. Bachl [aut, cph] (Fabian Bachl wrote the main code), David L. Borchers [ctb, dtc, cph] (David Borchers wrote code for Gorilla data import and sampling, multiplot tool), Daniel Simpson [ctb, cph] (Daniel Simpson wrote the basic LGCP sampling method), Lindesay Scott-Howard [ctb, dtc, cph] (Lindesay Scott-Howard provided MRSea data import code), Seaton Andy [ctb] (Andy Seaton provided testing and bugfixes)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.