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:
- 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.) - Set the cor namespace to that of
WGCNA
(viaWGCNA::cor
) and then resetting it back to the defaultstat
package (viastat::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?