From e0c4a9d4b8486bd41661ed1a86197aac0a5b4af4 Mon Sep 17 00:00:00 2001 From: Philippine Louail <127301965+philouail@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:37:03 +0200 Subject: [PATCH] Update MsExperiment.R --- R/MsExperiment.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/MsExperiment.R b/R/MsExperiment.R index 66bdba2..3711a42 100644 --- a/R/MsExperiment.R +++ b/R/MsExperiment.R @@ -267,15 +267,17 @@ setMethod("readMsObject", ## sample to spectra link fl <- object@spectra@backend@spectraData[1, "derived_spectral_data_file"] - nme <- colnames(merged_data)[which(merged_data[1, ] == fl)] + idx <- which(merged_data[1, ,drop = TRUE] == fl) + nme <- colnames(merged_data)[idx] merged_data <- merged_data[grepl(param@filePattern, merged_data[, nme]), ] - nme <- gsub(" ", "_", nme) #use concatenate instead ? + nme <- gsub(" ", "_", nme) + colnames(merged_data)[idx] <- nme object@sampleData <- DataFrame(merged_data, check.names = FALSE) object <- MsExperiment::linkSampleData(object, with = paste0("sampleData.", nme, - "= spectra.derived_spectral_data_file")) + "= spectra.derived_spectral_data_file")) validObject(object) object })