I have a function in a package I\'m building that assigns a hex-code to the global environment for use by analysts...
optiplum<-function(){
assign(
Assignment to the global environment is a no-no, see R Inferno and testthat isolates tests as much as possible (see test_that()
details). As a consequence, the optiplum()
assignment to the global environment would not succeed because the testthat function strictly prohibits such behaviour.
@Hadley rightly points out that the function should just return the string instead of assigning it, particularly since it is just two extra characters for each use.
So not
optiplum<-function(){
assign(
x="optiplum",
value=rgb(red=129,green=61,blue=114, maxColorValue = 255),
envir=.GlobalEnv)
}
but
optiplum <- function() rgb(red=102,green=17,blue=109, maxColorValue = 255)