I have a function in a package that I create that assigns hex code to a global environment for use by analysts ...
optiplum<-function(){
assign(
x="optiplum",
value=rgb(red=129,green=61,blue=114, maxColorValue = 255),
envir=.GlobalEnv)
}
My unit test code:
test_that("optiplum - produces the correct hex code",{
optiplum()
expect_true(identical(optiplum,"#813D72"))
})
When I run the code manually, there is no error:
> str(optiplum)
chr "#813D72"
> str("#813D72")
chr "#813D72"
> identical("#813D72",optiplum)
[1] TRUE
> expect_true(identical(optiplum,"#813D72"))
When test_file () is run, the error also fails
> test_file("./tests/testthat/test-optiplum.R")
optiplum : .
However, when I run the test as part of the devtools workflow:
> test()
Testing optINTERNAL
Loading optINTERNAL
optiplum : 1
1. Failure: optiplum - produces the correct hex code --------------------------------------------------------------------------------------------------------------
identical(optiplum, "#813D72") isn't true
Anyone have any ideas on why this could happen and how I can resolve the situation?
source
share