Some parts of my script that worked as intended at R version 4.03 stopped working after updating R to 4.1.
Reprex
library(tidyverse)
tibble(x = c("a or b", "not reported"),
y = c("c or d", "not reported")) %>%
mutate(across(c(x, y),
~str_to_title(.) %>%
str_replace_all(c(" Or " = " or ",
"Reported" = "reported")) %>%
{ifelse(. == "Not reported", NA, .)}))
This should return:
# A tibble: 2 x 2
x y
<chr> <chr>
1 A or B C or D
2 NA NA
But the actual output is:
# A tibble: 2 x 2
x y
<chr> <chr>
1 a or b c or d
2 not reported not reported
If I move the ifelse()
part into a separate mutate()
step,
tibble(x = c("a or b", "not reported"),
y = c("c or d", "not reported")) %>%
mutate(across(c(x, y),
~str_to_title(.) %>%
str_replace_all(c(" Or " = " or ",
"Reported" = "reported")))) %>%
mutate(across(c(x, y), ~ifelse(. == "Not reported", NA, .)))
It works as intended.
# A tibble: 2 x 2
x y
<chr> <chr>
1 A or B C or D
2 NA NA
Is this a bug?