From cae897dc6d616ddfb79e80b4649016307f315fdc Mon Sep 17 00:00:00 2001 From: Damien RAT Date: Tue, 5 Nov 2024 15:56:24 +0100 Subject: [PATCH] fix: psg_list (findAdducts) and sample (xsAnnotate) v2 --- tools/camera/CAMERA_findAdducts.R | 20 +++++++++++++------- tools/camera/CAMERA_groupFWHM.R | 8 +++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/camera/CAMERA_findAdducts.R b/tools/camera/CAMERA_findAdducts.R index 470516103..7db8ea742 100755 --- a/tools/camera/CAMERA_findAdducts.R +++ b/tools/camera/CAMERA_findAdducts.R @@ -33,14 +33,16 @@ convertNullString <- function(x) { return(x) } -for (arg in names(args)) { - args[[arg]] <- convertNullString(args[[arg]]) -} - -# Function to convert string to numeric lists +# Function to convert string to numeric lists or NA convertStringToNumeric <- function(x) { - if (x == NULL) { - return(x) + # Force conversion to character + x <- as.character(x) + + if (x == "NA") { + return(NA) + } else if (grepl("^[0-9]+$", x)) { + # If the string represents a single numeric value + return(as.numeric(x)) } else { # Convert string representation of a list to a numeric vector # Use a regular expression to split by common separators @@ -48,6 +50,10 @@ convertStringToNumeric <- function(x) { } } +for (arg in names(args)) { + args[[arg]] <- convertNullString(args[[arg]]) +} + # Convert only the 'psg_list' element in args args$psg_list <- convertStringToNumeric(args$psg_list) diff --git a/tools/camera/CAMERA_groupFWHM.R b/tools/camera/CAMERA_groupFWHM.R index a02b90689..afe50351e 100755 --- a/tools/camera/CAMERA_groupFWHM.R +++ b/tools/camera/CAMERA_groupFWHM.R @@ -25,10 +25,16 @@ cat("\n\n") print("Arguments retrieved from the command line:") print(args) -# Function to convert "NA" strings to actual NA values and string to numeric lists +# Function to convert "NA" strings to actual NA values and string lists to numeric lists convertStringToNumeric <- function(x) { + # Force conversion to character + x <- as.character(x) + if (x == "NA") { return(NA) + } else if (grepl("^[0-9]+$", x)) { + # If the string represents a single numeric value + return(as.numeric(x)) } else { # Convert string representation of a list to a numeric vector # Use a regular expression to split by common separators