Skip to content

Error arised while identifying ROIs in m/z dimensions.... #378

Description

@rogasan

Ubuntu 24.04 + R 4.6.1 + MetaboAnalystR 4.30 + OptiLCMS 1.20:

mSet_ROI <- PerformROIExtraction(datapath = DataFiles, rt.idx = 0.9, rmConts = TRUE)
Step 0/6: Scanning ROIs for parameters optimization...
QC_01.mzML
QC_02.mzML
QC_03.mzML
QC_04.mzML
QC_05.mzML
Data Loading...
Raw file import begin...
Import data: QC_01.mzML finished!
Import data: QC_02.mzML finished!
Import data: QC_03.mzML finished!
Import data: QC_04.mzML finished!
Import data: QC_05.mzML finished!
Data Loaded !
Empty Scan detecting...
No Empty scan found !
Identifying regions of interest (ROI)...
Identifying regions of potential contaminants......Done!
51 potential contaminamts will not be used for parameters optimization !
Going to the next step...
MS data Preparing...
MS Data ready !
Identifying ROIs in m/z dimensions...
Error in x > good.bins.list[[4]][[1]] && x < good.bins.list[[4]][[2]] :
'length = 4' in coercion to 'logical(1)'

Gmini 3.1 Pro Says:

This error is caused by a strict rule change introduced in R version 4.3.0.

In older versions of R, using the scalar logical operator && on a vector (an object with a length greater than 1, like your x which has a length of 4) would only generate a warning. Starting with R 4.3.0, doing this triggers a hard error: 'length = 4' in coercion to 'logical(1)'.

This is a known bug in the source code of the OptiLCMS / MetaboAnalystR package where the developers accidentally used && instead of the vectorized & operator.

Here are the ways to fix this:

Option 1: Update the Packages (Recommended)
The Xia Lab (creators of MetaboAnalystR) frequently patches these R 4.3+ compatibility bugs on their GitHub repository. You should reinstall the latest versions of OptiLCMS and MetaboAnalystR directly from GitHub rather than CRAN.

Run this in your R console:

R

Install devtools if you haven't already

if (!requireNamespace("devtools", quietly = TRUE))
install.packages("devtools")

Force update OptiLCMS and MetaboAnalystR from GitHub

devtools::install_github("xia-lab/OptiLCMS", force = TRUE)
devtools::install_github("xia-lab/MetaboAnalystR", force = TRUE)
After updating, restart your R session and run your PerformROIExtraction code again.

Option 2: Downgrade R to version 4.2.3
If the developers haven't pushed a fix for this specific line of code yet, the easiest workaround is to temporarily downgrade your R installation to R 4.2.3.

In R 4.2.3, the expression x > good.bins.list[[4]][[1]] && x < good.bins.list[[4]][[2]] will only throw a silent warning and will successfully evaluate the first element, allowing your data pipeline to finish running without crashing.

Option 3: Clean your Global Environment
Occasionally, corrupted metadata in your current R environment can pass unexpectedly long vectors into the ROI function. If Option 1 doesn't work and you prefer not to downgrade R, try clearing your environment and recreating the DataFiles object:

R

Clear environment

rm(list = ls())

Re-initialize your path and run

DataFiles <- "path_to_your_data"
mSet_ROI <- PerformROIExtraction(datapath = DataFiles, rt.idx = 0.9, rmConts = TRUE)

Please fix it and refresh the OptiLCMS packages....

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions