Skip to content

Commit

Permalink
ifelse -> if_else
Browse files Browse the repository at this point in the history
  • Loading branch information
Adafede committed Jan 16, 2025
1 parent 2f7f138 commit 7f0ed77
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 65 deletions.
76 changes: 40 additions & 36 deletions R/annotate_masses.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 = "_")))
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions R/annotate_spectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) |>
Expand Down
8 changes: 4 additions & 4 deletions R/clean_bio.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
}
Expand Down
8 changes: 4 additions & 4 deletions R/clean_collapse.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = " $ "))
Expand Down
16 changes: 8 additions & 8 deletions R/harmonize_spectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/prepare_libraries_rt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) |>
Expand Down
8 changes: 4 additions & 4 deletions R/weight_bio.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
Expand Down
8 changes: 4 additions & 4 deletions inst/_targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7f0ed77

Please sign in to comment.