r devtools test() errors but testthat test_file() works

隐身守侯 提交于 2019-12-01 18:54:50

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!