【发布时间】:2016-06-26 20:07:24
【问题描述】:
我有这个问题。我正在为 R 创建一个名为“mypackagefunction”的新包,其部分代码是这个
mypackagefunction<-function(){
##This is the constructor of my package
##1st step: define variables
gdata <<- NULL
#...
#below of this, there are more functions and code
}
所以,我在 R Studio 中构建并重新加载,然后检查并在此步骤中收到以下警告:
mypackagefunction: '
但是当我运行我的包时:
mypackagefunction()
我可以用这个结果调用包中的那个变量
> mypackagefunction()
> gdata
NULL
当我检查我的包裹时,如何删除此注意或警告?或其他方式来定义全局变量?
【问题讨论】:
-
你不应该在包中定义全局变量。 CRAN 可能不会接受。
-
它在CRAN Repository Policy 中,在Source Packages 的最后一节中写着Packages should not modify the global environment(user's workspace)。