我想在我的 .Rprofile 中加入以下函数,以便更轻松地安装 bioconductor 包:
install.bioconductor <- function(...) {
source("http://bioconductor.org/biocLite.R")
biocLite(...)
}
但是当我加载一个新的 R 会话时,这个函数现在在我调用ls
. 有没有一种方法可以屏蔽该功能的显示?
您可以将其放在自己的环境中并将该环境附加到搜索路径。
myFUNs <- new.env()
myFUNs$install.bioconductor <- function(...) {
source("http://bioconductor.org/biocLite.R")
biocLite(...)
}
attach(myFUNs) # attach to the search path
rm(myFUNs) # remove from .GlobalEnv
# it is still accessible via
# install.bioconductor(...)
然后它可以访问,但不会显示在ls()
. (您可以看到附加到搜索路径的search()
内容,您可以看到myFUNs
其中的内容ls(myFUNs)
)
或者,正如@JoshuaO'Brien 在评论中提到的那样,您可以将其保留在 中,.GlobalEnv
但在名称的开头添加一个点(即命名它.install.bioconductor
),这样它将被“隐藏”,这样它就不会显示为ls()
,但会出现ls(all.names=TRUE)
.