propr icon indicating copy to clipboard operation
propr copied to clipboard

aldex.glm expects different input in propr vs aldex2 packages, leading to errors when both are loaded

Open rrohwer opened this issue 2 years ago • 0 comments

I am trying to use both the propr and alex2 packages, but am getting errors with the aldex.glm function because depending on which package took precedence in loading it is either expecting or not expecting a model matrix to be provided as an argument.

Example workflow that's inconsistently giving me errors:

library(zCompositions)
library(propr)
library(ALDEx2)

otus <- readRDS(...)
otus <- cmultRepl(X = otus, z.warning = .9) 
covariates <- data.frame("A" = ..., "B" = ...)
mm <- model.matrix(~ A + B, covariates)
otus.aldex <- aldex.clr(reads = otus, conds = mm, ...)
otus.propr <- aldex2propr(alrex.clr = otus.aldex, how = "rho")
otus.clr <- otus.propr@logratio

otus.glm <- aldex.glm(clr = otus.aldex) # or sometimes it wants aldex.glm(clr = otus.aldex, mm)

otus.effect <- aldex.glm.effect(clr = otus.aldex)

And I solve the problem by doing this:

library(zCompositions)
detach("package:propr", unload=TRUE)
library(ALDEx2)

otus <- readRDS(...)
otus <- cmultRepl(X = otus, z.warning = .9) 
covariates <- data.frame("A" = ..., "B" = ...)
mm <- model.matrix(~ A + B, covariates)
otus.aldex <- aldex.clr(reads = otus, conds = mm, ...)
otus.glm <- aldex.glm(clr = otus.aldex) 
otus.effect <- aldex.glm.effect(clr = otus.aldex)

library(propr) # load propr AFTER using aldex2 package
otus.propr <- aldex2propr(alrex.clr = otus.aldex, how = "rho")
otus.clr <- otus.propr@logratio

Since these packages are designed to be used together, I thought you might consider this incompatibility a bug.

Thanks, Robin

rrohwer avatar Mar 11 '22 15:03 rrohwer