@@ -152,37 +152,39 @@ insert_specific_atc <- function(data, proportion = 0.3) {
152
152
# Insert a few cases where purchases of metformin are used for other purposes
153
153
# than diabetes.
154
154
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
+ )
169
168
)
170
- )
169
+ } else {
170
+ return (data )
171
+ }
171
172
}
172
173
173
174
# Insert some false positives for Wegovy and Saxenda.
174
175
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 {
176
186
return (data )
177
187
}
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
- )
186
188
}
187
189
188
190
insert_analysiscode <- function (data , proportion = 0.3 ) {
0 commit comments