fluffyflea
fluffyflea

Reputation: 21

Why does wrapper function result in error

I'm trying to include a function from the Bioconductor package "simpIntLists" in my own package. "import(simpIntLists)" is added to the Namespace file. However, the function results in an error

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)

It works fine when simpIntLists is attached

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

Upvotes: 1

Views: 91

Answers (1)

Kota Mori
Kota Mori

Reputation: 6740

I saw the code here (https://bioconductor.org/packages/release/data/experiment/html/simpIntLists.html). This code does not seem to take into account the situation where the package is used without installation.

For your information, the relevant part to this error is around the line 52.

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

It tries to fetch the data to the namespace but it fails to do so if the package is not imported via library yet. This only generates a warning. The error then occurs when it tries to use the data because it does not exist in the namespace.

A workaround is that you import the data in your code explicitly. Then you can use the function as below. Note that the warning remains because of the embedded package code. If the warning is annoying, use suppressWarnings.

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

Upvotes: 1

Related Questions