【问题标题】:Why does wrapper function result in error为什么包装函数会导致错误
【发布时间】:2021-11-04 10:59:50
【问题描述】:

我正在尝试将 Bioconductor 包“simpIntLists”中的一个函数包含在我自己的包中。 “import(simpIntLists)”被添加到命名空间文件中。 但是,该函数导致错误

do_xy <- function(organism, IDType){
network <- simpIntLists::findInteractionList(organism, IDType)
}

do_xy("human", "EntrezId")

#Error message
data set ‘HumanBioGRIDInteractionEntrezId’ not foundError in get("HumanBioGRIDInteractionEntrezId") : 
  object 'HumanBioGRIDInteractionEntrezId' not found

# results in the same error (outside of the function)
simpIntLists::findInteractionList(organism, IDType)

附加 simpIntLists 后效果很好

# works 
library(simpIntLists) 
network <- simpIntLists::findInteractionList(organism, IDType)

【问题讨论】:

  • 您能否提供更多细节? simpIntLists 包从何而来?你是什​​么意思你把它添加到命名空间? network 行不在函数中时是否有效?

标签: r r-package


【解决方案1】:

我在这里看到了代码 (https://bioconductor.org/packages/release/data/experiment/html/simpIntLists.html)。 这段代码似乎没有考虑包不安装就使用的情况。

供您参考,此错误的相关部分在第 52 行附近。

else if (organism == 'human'){
  if (idType == 'EntrezId'){
    data(HumanBioGRIDInteractionEntrezId);
    interactionList <- get("HumanBioGRIDInteractionEntrezId");
  }

它会尝试将数据提取到命名空间,但如果尚未通过library 导入包,它就会失败。这只会产生警告。然后当它尝试使用数据时会发生错误,因为它在命名空间中不存在。

一种解决方法是在代码中显式导入数据。然后您可以使用如下功能。请注意,由于嵌入的包代码,警告仍然存在。如果警告很烦人,请使用suppressWarnings

data(HumanBioGRIDInteractionEntrezId, package="simpIntLists")
simpIntLists::findInteractionList("human", "EntrezId")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    相关资源
    最近更新 更多