From 9851a98b245a0f9f5453d2c6ac0403c9e259a5c0 Mon Sep 17 00:00:00 2001 From: Wesley Brooks Date: Wed, 18 Sep 2024 12:41:16 -0700 Subject: [PATCH] keep PC matrix 2-dimensional even if only one PC The prior code will fail when only one PC is selected because by default R will drop the singleton dimension and then the result is not an array type, so `dimnames(PCs)` generates an error. adding `drop = FALSE` to the subset keeps the singe PC as a column matrix, so everything will work. --- R/Examine_Region_Methylation.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/Examine_Region_Methylation.R b/R/Examine_Region_Methylation.R index 0f506ff..11d790b 100644 --- a/R/Examine_Region_Methylation.R +++ b/R/Examine_Region_Methylation.R @@ -161,7 +161,7 @@ getPCs <- function(meth, mod = matrix(1, nrow = ncol(meth), ncol = 1), meth_t <- t(meth) meth_t_centered <- scale(meth_t, center = TRUE, scale = FALSE) ss <- svd(meth_t_centered) - PCs <- ss$u[, 1:n.pc] + PCs <- ss$u[, 1:n.pc, drop=FALSE] dimnames(PCs) <- list(dimnames(meth_t)[[1]], paste0("PC_", 1:n.pc)) if(save){ if(verbose){