Skip to content

Commit a3ad8cc

Browse files
committed
fix: flip the condition so it's true when both "atc" and "name" is in data
1 parent e622149 commit a3ad8cc

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

data-raw/simulate-data.R

+26-24
Original file line numberDiff line numberDiff line change
@@ -152,37 +152,39 @@ insert_specific_atc <- function(data, proportion = 0.3) {
152152
# Insert a few cases where purchases of metformin are used for other purposes
153153
# than diabetes.
154154
insert_false_metformin <- function(data, proportion = 0.05) {
155-
if (!all(colnames(data) %in% c("atc", "name"))) {
156-
return(data)
157-
}
158-
data |>
159-
dplyr::mutate(
160-
atc = dplyr::if_else(
161-
indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion),
162-
"A10BA02",
163-
atc
164-
),
165-
name = dplyr::if_else(
166-
indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion),
167-
"metformin",
168-
name
155+
if (all(c("atc", "name") %in% colnames(data))) {
156+
data |>
157+
dplyr::mutate(
158+
atc = dplyr::if_else(
159+
indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion),
160+
"A10BA02",
161+
atc
162+
),
163+
name = dplyr::if_else(
164+
indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion),
165+
"metformin",
166+
name
167+
)
169168
)
170-
)
169+
} else {
170+
return(data)
171+
}
171172
}
172173

173174
# Insert some false positives for Wegovy and Saxenda.
174175
insert_false_drug_names <- function(data, proportion = 0.05) {
175-
if (!all(colnames(data) %in% c("atc", "name"))) {
176+
if (all(c("atc", "name") %in% colnames(data))) {
177+
data |>
178+
mutate(
179+
name = case_when(
180+
atc == "A10BJ06" & insertion_rate(proportion) ~ "Wegovy Flextouch",
181+
atc == "A10BJ02" & insertion_rate(proportion) ~ "Saxenda",
182+
TRUE ~ name
183+
)
184+
)
185+
} else {
176186
return(data)
177187
}
178-
data |>
179-
mutate(
180-
name = case_when(
181-
atc == "A10BJ06" & insertion_rate(proportion) ~ "Wegovy Flextouch",
182-
atc == "A10BJ02" & insertion_rate(proportion) ~ "Saxenda",
183-
TRUE ~ name
184-
)
185-
)
186188
}
187189

188190
insert_analysiscode <- function(data, proportion = 0.3) {

0 commit comments

Comments
 (0)