I have a function that one of it’s duties is to is perform a batch effect correction, and that is according to the use_batch
parameter which takes a boolian value. (it’s a parameter that is passed when calling the function).
This is the part of the function that perform this correction:
if (use_batch){
scores = as.data.frame(scores)
cancer.type = metadata[['Cancer_Type']]
scores = limma::removeBatchEffect(t(scores) ,batch = cancer.type)
scores = t(scores)
}
Produces this error:
Error in rowMeans(y$exprs, na.rm = TRUE) : 'x' must be numeric
And this code works fine outside the function. my_scores
and my_meta
are the real dataframes that I use:
> if (TRUE){
scoresx = as.data.frame(my_scores)
cancer.type = my_meta[['Cancer_Type']]
scoresx = limma::removeBatchEffect(t(scoresx) ,batch = cancer.type)
scoresx = t(scoresx)
}
It’s important to note that the function works perfectly when use_batch = FALSE
, therefore the problem is only with this chunk I provided here. The Show Traceback option tells me the problem is here: scores = limma::removeBatchEffect(t(scores) ,batch = cancer.type)
. What is the problem? why does it work good outside the function? Here are small subsets of the two used dataframes in the function:
> dput(my_scores[1:6,1:6])
structure(c(-0.0741098696855045, -0.094401270881699, 0.0410284948786532,
-0.163302950330185, -0.0942478217207681, -0.167314411991775,
-0.178835447722468, -0.253897294559596, -0.0372301980787381,
-0.230579110769457, -0.224125346052727, -0.196933050675633, -0.0384421660291032,
-0.0275306107582565, 0.186447606591857, -0.124972070102036, -0.15348122673842,
-0.106812144494277, -0.0924083910597563, -0.172356328661097,
-0.0172673823614314, 0.0280649471541352, -0.128925304635747,
-0.0875076743713435, -0.0680848706469295, -0.173427291586957,
-0.0106773958944477, -0.0015805672257001, -0.0751114943036091,
-0.0737177243152751, -0.0391833488213571, -0.0275279418713283,
0.0156454755097513, 0.0285160860867748, -0.0633367938488132,
0.0252778805872529), dim = c(6L, 6L), dimnames = list(c("Pt1",
"Pt10", "Pt101", "Pt103", "Pt106", "Pt11"), c("CD4-T-cells",
"CD8-T-cells", "T-helpers", "NK-cells", "Monocytes", "Neutrophils"
)))
> View(dput(my_meta[1:6,2:7]))
structure(list(samples = c("Pt1", "Pt10", "Pt101", "Pt103", "Pt106",
"Pt11"), Response = c("NoResponse", "NoResponse", "Response",
"NoResponse", "NoResponse", "NoResponse"), RECIST = c("PD", "SD",
"PR", "PD", "PD", "PD"), Gender = c("male", "female", "female",
"female", "male", "female"), treatment = c("anti-PD1", "anti-PD1",
"anti-PD1", "anti-PD1", "anti-PD1", "anti-PD1"), Cancer_Type = c("Melanoma",
"Melanoma", "Melanoma", "Melanoma", "Melanoma", "Melanoma")), row.names = c("Pt1",
"Pt10", "Pt101", "Pt103", "Pt106", "Pt11"), class = "data.frame")