# ---------------------------------------------------------------------------- #
test_that("place_in_env writes object to specified env and not current env", {
an_env <- new.env(parent = emptyenv())
place_in_env(x = 1, y = 2, envir = an_env)
is_found <- exists("x", envir = environment(), inherits = FALSE)
expect_false(is_found)
})
# ---------------------------------------------------------------------------- #
test_that("object put in specific env gives not found error from default env", {
an_env <- new.env(parent = emptyenv())
place_in_env(x = 1, y = 2, envir = an_env)
expect_snapshot(y + 1, error = TRUE)
})
# ---------------------------------------------------------------------------- #
test_that("object put in specific env exists when retrieved", {
an_env <- new.env(parent = emptyenv())
place_in_env(x = 1, y = 2, envir = an_env)
expect_true(exists("y", envir = an_env))
})
# ---------------------------------------------------------------------------- #
test_that("object put into env equals expected value", {
an_env <- new.env(parent = emptyenv())
place_in_env(x = 1, y = 2, envir = an_env)
expect_equal(an_env$x, 1)
expect_equal(an_env$y, 2)
})
# ---------------------------------------------------------------------------- #
test_that("place_in_env with default env does not save object to curr env", {
# this will place the variables in the environment local to place_in_env
place_in_env(x = 1)
is_found <- exists("x", envir = environment(), inherits = FALSE)
expect_false(is_found)
})
# ---------------------------------------------------------------------------- #
test_that("place_in_env sets explicit names", {
an_env <- new.env(parent = emptyenv())
place_in_env(x = 1, y = 2, envir = an_env, var_names = c("one", "two"))
expect_false(exists("x", envir = an_env))
expect_true(exists("two", envir = an_env))
})
# ---------------------------------------------------------------------------- #
test_that("place_in_env sets default names", {
an_env <- new.env(parent = emptyenv())
place_in_env("apple", "pear", envir = an_env)
expect_equal(an_env$b, "pear")
})
# ---------------------------------------------------------------------------- #
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.