Skip to content

Commit

Permalink
fix: psg_list (findAdducts) and sample (xsAnnotate) v2
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCode404 committed Nov 5, 2024
1 parent 43e7c4a commit cae897d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
20 changes: 13 additions & 7 deletions tools/camera/CAMERA_findAdducts.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ 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
return(as.numeric(unlist(strsplit(x, "[,;\\s]+"))))
}
}

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)

Expand Down
8 changes: 7 additions & 1 deletion tools/camera/CAMERA_groupFWHM.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cae897d

Please sign in to comment.