0

I'm using a function from the WGCNA package that has a parameter corType which takes a string input of the specific correlation you want to run. Two of the main correlation methods are "pearson" and "bicor". When I run the function I get an error when the function gets to processing the corType parameter. If I run "pearson" I get the error:

Error in (function(x, y - NULL, use = "everything", method = c("pearson", unused arguments (weights.x = NULL, weights.y = NULL,
cosine = FALSE)

If I run the function with corType as "bicor" I get the error:

Error in get(as.character(FUN), mode = "function", envir = envir) : 
  object 'bicor' of mode 'function' was not found

I did some searching on biostars and it seemed like WGCNA was running into a shared namespace problem. An old post suggested that I do one of two things:

  1. Restart R and only load the WGCNA package before running the function (which seems silly, since I might run the function several times in a day.)
  2. Set the cor namespace to that of WGCNA (via WGCNA::cor) and then resetting it back to the default stat package (via stat::cor). Which seems better but might still be clunky.

Below I have tried to include a minimally reproducible example as well as my R session info. It's probably important to mention that I'm building a package so when I run the WGCNA functions its within another function and instead of using require() for each package I add them to the imports in the DESCRIPTION and call a function within those packages using foo::bar. I have run the following code in my own R environment and duplicated the errors. Please let me know if you need any further in formation.

cnames = c("GSM2886523", "GSM2886524", "GSM2886525", "GSM2886526", "GSM2886527")
test.expr.data <- matrix(c(0.1708434,-0.1129639,-0.09490149,-0.08757270,0.08918957, 
                           0.9866739,-1.0146009,-2.18310607,-1.92989284,-2.01153493, 
                           -0.1447803,0.2311808,-0.09179321,-0.16356002,-0.19043491, 
                           -0.2162092,0.2822163,0.06230056,-0.03903165,0.53407426, 
                           -0.2659731,0.1810084,0.02749196,-0.07015478,-0.07480163), 
                           nrow = 5, ncol = 5)
colnames(test.expr.data) <- cnames

wgcna_out = WGCNA::blockwiseModules(t(expr_data), power = 5, networkType = "signed", 
                                    corType = "pearson")
#Error in (function(x, y - NULL, use = "everything", method = c("pearson", unused arguments (weights.x = NULL, weights.y = NULL,
#cosine = FALSE)

wgcna_out = WGCNA::blockwiseModules(t(expr_data), power = 5, networkType = "signed", 
                                    corType = "bicor")
#Error in get(as.character(FUN), mode = "function", envir = envir) : 
#  object 'bicor' of mode 'function' was not found

Should I set and then reset the cor namespace each time I run this function or is there a more elegant way to do work around this problem?

R session info.

Jeffrey Brabec
  • 481
  • 6
  • 11
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Don't just show the error, show the code you were running to get the error as well. What other packages do you have loaded? – MrFlick Aug 12 '19 at 20:24
  • 1
    I would consider this as a bug in WGCNA. Without a reproducible example and limited time I am somewhat discouraged from going down the rabbit hole and finding a definitive solution but the root of the issue is their `.corFnc` variable where functions are named without explicitly calling their namespace. I believe changing `.corFnc` to `c("WGCNA::cor", "WGCNA::bicor", "WGCNA::cor")` would solve the issue but there might be downstream errors since I see a few examples of string matching in their code. String matching seems to be done on `.corTypes` so it could be an easy fix. – OganM Aug 12 '19 at 21:46
  • 1
    The problematic file is `internalConstants.R`. You can get a clone of WGCNA from `https://github.com/cran/WGCNA`. If a fix is found, WGCNA people should probably be told about it. Will stop by later myself if I have the time – OganM Aug 12 '19 at 21:49
  • Thanks for all your helpful comments! I've updated my question to be a little more helpful to you all. – Jeffrey Brabec Aug 13 '19 at 14:59

1 Answers1

1

I'm aware of this problem; at present I simply use

cor=WGCNA::cor

before I run WGCNA code.

I'll have to check on the bicor problem, that should not happen.