diff --git a/R/annotate_masses.R b/R/annotate_masses.R index cfd6636f..49ba3377 100644 --- a/R/annotate_masses.R +++ b/R/annotate_masses.R @@ -257,23 +257,25 @@ annotate_masses <- tidytable::left_join(clusters_table |> tidytable::mutate(join = "x")) |> tidytable::bind_rows(adducts_table) |> - tidytable::mutate(adduct = ifelse( - test = !is.na(cluster), - yes = paste0( - adduct |> gsub( - pattern = "M(?![a-z]).*", - replacement = "M", - perl = TRUE - ), + tidytable::mutate(adduct = tidytable::if_else( + condition = !is.na(cluster), + true = paste0( + adduct |> + gsub( + pattern = "M(?![a-z]).*", + replacement = "M", + perl = TRUE + ), "+", cluster, - adduct |> gsub( - pattern = ".*M(?![a-z])", - replacement = "", - perl = TRUE - ) + adduct |> + gsub( + pattern = ".*M(?![a-z])", + replacement = "", + perl = TRUE + ) ), - no = adduct + false = adduct )) |> # Single charge monomers only tidytable::filter(grepl( @@ -332,15 +334,15 @@ annotate_masses <- tidytable::filter(!is.na(Group1)) |> tidytable::mutate(tidytable::across(.cols = c("rt"), .fns = as.character)) |> tidytable::mutate( - adduct = ifelse( - test = is.na(adduct), - yes = as.character(Group1), - no = adduct + adduct = tidytable::if_else( + condition = is.na(adduct), + true = as.character(Group1), + false = adduct ), - adduct_dest = ifelse( - test = is.na(adduct_dest), - yes = as.character(Group2), - no = adduct_dest + adduct_dest = tidytable::if_else( + condition = is.na(adduct_dest), + true = as.character(Group2), + false = adduct_dest ) ) |> tidytable::distinct(feature_id, adduct, adduct_dest, !!as.name(paste("feature_id", "dest", sep = "_"))) @@ -380,23 +382,25 @@ annotate_masses <- tidytable::left_join(df_nl_min) |> tidytable::bind_rows(df_adducted) |> tidytable::distinct() |> - tidytable::mutate(adduct = ifelse( - test = !is.na(loss), - yes = paste0( - adduct |> gsub( - pattern = "M(?![a-z]).*", - replacement = "M", - perl = TRUE - ), + tidytable::mutate(adduct = tidytable::if_else( + condition = !is.na(loss), + true = paste0( + adduct |> + gsub( + pattern = "M(?![a-z]).*", + replacement = "M", + perl = TRUE + ), "-", loss, - adduct |> gsub( - pattern = ".*M(?![a-z])", - replacement = "", - perl = TRUE - ) + adduct |> + gsub( + pattern = ".*M(?![a-z])", + replacement = "", + perl = TRUE + ) ), - no = adduct + false = adduct )) rm(df_adducted, df_nl_min) diff --git a/R/annotate_spectra.R b/R/annotate_spectra.R index 075087e2..d326e8a3 100644 --- a/R/annotate_spectra.R +++ b/R/annotate_spectra.R @@ -248,15 +248,15 @@ annotate_spectra <- function(input = get_params(step = "annotate_spectra")$files df_final <- df_final |> tidytable::mutate( candidate_structure_error_mz = target_precursorMz - precursorMz, - candidate_structure_inchikey_no_stereo = ifelse( - test = is.na(target_inchikey_no_stereo), - yes = target_inchikey |> + candidate_structure_inchikey_no_stereo = tidytable::if_else( + condition = is.na(target_inchikey_no_stereo), + true = target_inchikey |> gsub( pattern = "-.*", replacement = "", perl = TRUE ), - no = target_inchikey_no_stereo + false = target_inchikey_no_stereo ), candidate_structure_smiles_no_stereo = tidytable::coalesce(target_smiles_no_stereo, target_smiles) ) |> diff --git a/R/clean_bio.R b/R/clean_bio.R index ede03ae2..876a0890 100644 --- a/R/clean_bio.R +++ b/R/clean_bio.R @@ -94,10 +94,10 @@ clean_bio <- feature_source, !!as.name(feature_val_name) := !!as.name(candidates), !!as.name(consistency_name), !!as.name(feature_score_name) ) |> tidytable::mutate( - !!as.name(feature_val_name) := ifelse( - test = !!as.name(feature_score_name) >= minimal_consistency, - yes = !!as.name(feature_val_name), - no = "notConsistent" + !!as.name(feature_val_name) := tidytable::if_else( + condition = !!as.name(feature_score_name) >= minimal_consistency, + true = !!as.name(feature_val_name), + false = "notConsistent" ) ) } diff --git a/R/clean_collapse.R b/R/clean_collapse.R index 5e59e8a7..140f8115 100644 --- a/R/clean_collapse.R +++ b/R/clean_collapse.R @@ -11,10 +11,10 @@ clean_collapse <- function(grouped_df, cols = NA) { clean_collapse_df <- grouped_df |> tidytable::reframe(tidytable::across( - .cols = ifelse( - test = is.na(cols), - yes = tidyselect::everything(), - no = cols + .cols = tidytable::if_else( + condition = is.na(cols), + true = tidyselect::everything(), + false = cols ), .fns = function(x) { x <- list(paste(unique(x[!is.na(x)]), collapse = " $ ")) diff --git a/R/harmonize_spectra.R b/R/harmonize_spectra.R index 87db3794..51a9accf 100644 --- a/R/harmonize_spectra.R +++ b/R/harmonize_spectra.R @@ -151,15 +151,15 @@ harmonize_spectra <- function(spectra, tidytable::mutate( library = metad, exactmass = as.numeric(exactmass), - spectrum_id = ifelse( - test = is.na(spectrum_id), - yes = tidytable::row_number(), - no = as.numeric(spectrum_id) + spectrum_id = tidytable::if_else( + condition = is.na(spectrum_id), + true = tidytable::row_number(), + false = as.numeric(spectrum_id) ), - compound_id = ifelse( - test = is.na(compound_id), - yes = name, - no = compound_id + compound_id = tidytable::if_else( + condition = is.na(compound_id), + true = name, + false = compound_id ) ) |> data.frame() diff --git a/R/prepare_libraries_rt.R b/R/prepare_libraries_rt.R index 0e34dd6a..0c20c359 100644 --- a/R/prepare_libraries_rt.R +++ b/R/prepare_libraries_rt.R @@ -152,7 +152,7 @@ prepare_libraries_rt <- data.frame() |> tidytable::mutate(type = type) |> tidytable::rowwise() |> - tidytable::mutate(rt = ifelse(unit == "seconds", yes = as.numeric(rt) / 60, no = rt)) |> + tidytable::mutate(rt = tidytable::if_else(condition = unit == "seconds", true = as.numeric(rt) / 60, false = rt)) |> tidytable::bind_rows(data.frame(inchikey = NA_character_, smiles = NA_character_)) |> tidytable::filter(!is.na(rt)) |> tidytable::filter(!is.na(smiles)) |> diff --git a/R/weight_bio.R b/R/weight_bio.R index 227f938d..840ce95a 100644 --- a/R/weight_bio.R +++ b/R/weight_bio.R @@ -177,10 +177,10 @@ weight_bio <- !!as.name(samples) == "notClassified" ) |> tidytable::mutate( - !!as.name(score_name) := ifelse( - test = !!as.name(samples) != "notClassified", - yes = !!as.name(score) * 1, - no = 0 + !!as.name(score_name) := tidytable::if_else( + condition = !!as.name(samples) != "notClassified", + true = !!as.name(score) * 1, + false = 0 ) ) } diff --git a/inst/_targets.R b/inst/_targets.R index 0a25e950..260d3e95 100644 --- a/inst/_targets.R +++ b/inst/_targets.R @@ -2010,10 +2010,10 @@ list( rtime = tidytable::cur_group_id(), .by = "short_ik" ) |> - tidytable::mutate(precursorCharge = ifelse( - test = mode == "pos", - yes = as.integer(1), - no = as.integer(-1) + tidytable::mutate(precursorCharge = tidytable::if_else( + condition = mode == "pos", + true = as.integer(1), + false = as.integer(-1) )) |> tidytable::select( acquisitionNum,