首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么包装器函数会导致错误

为什么包装器函数会导致错误
EN

Stack Overflow用户
提问于 2021-11-04 10:59:51
回答 1查看 36关注 0票数 1

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

代码语言:javascript
复制
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时,它工作正常

代码语言:javascript
复制
# works 
library(simpIntLists) 
network <- simpIntLists::findInteractionList(organism, IDType)
EN

回答 1

Stack Overflow用户

发布于 2021-11-04 13:24:51

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

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

代码语言:javascript
复制
else if (organism == 'human'){
  if (idType == 'EntrezId'){
    data(HumanBioGRIDInteractionEntrezId);
    interactionList <- get("HumanBioGRIDInteractionEntrezId");
  }

它会尝试将数据获取到名称空间,但如果还没有通过library导入包,则会失败。这只会生成一个警告。然后,当它尝试使用该数据时就会出现错误,因为该数据在命名空间中不存在。

一种解决方法是在代码中显式导入数据。然后您可以使用如下所示的函数。请注意,由于嵌入的包代码,该警告仍然存在。如果警告令人讨厌,请使用suppressWarnings

代码语言:javascript
复制
data(HumanBioGRIDInteractionEntrezId, package="simpIntLists")
simpIntLists::findInteractionList("human", "EntrezId")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69838164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档