From 952757a31347dea46f29703d15f83c02408dd821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Signe=20Kirk=20Br=C3=B8db=C3=A6k?= Date: Fri, 26 Apr 2024 17:17:15 +0200 Subject: [PATCH 1/6] docs: :art: add documentation to simulation functions --- data-raw/simulate-data.R | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/data-raw/simulate-data.R b/data-raw/simulate-data.R index 00d83fb..ab5b3c9 100644 --- a/data-raw/simulate-data.R +++ b/data-raw/simulate-data.R @@ -29,12 +29,33 @@ library(rvest) # Simulation functions ----------------------------------------------------- +#' Zero pad integers +#' +#' @param x An integer or vector of integers +#' @param width An integer describing the final width of the zero-padded integer +#' @keywords internal +#' +#' @return A zero padded integer +#' +#' @examples +#' pad_integers(x=1, width=5) +#' pad_integers(x=c(1,2,3), width=10) pad_integers <- function(x, width) { x |> stringr::str_trunc(width = width, side = "left", ellipsis = "") |> stringr::str_pad(width = width, side = "left", pad = "0") } +#' Create ICD diagnoses. +#' +#' @param n The number of ICD-10 diagnoses to generate. +#' @param date A date determining whether the diagnoses should be ICD-8 or ICD-10. If null, a random date will be sampled to determine which ICD revision the diagnosis should be from. +#' +#' @return n ICD-10 diagnoses as characters. +#' +#' @examples +#' create_fake_icd(10) +#' #' create_fake_icd(5, "1995-04-19") create_fake_icd <- function(n, date = NULL) { if (is.null(date)) { date <- sample(c("1993-01-01", "1995-01-01"), 1) @@ -47,6 +68,16 @@ create_fake_icd <- function(n, date = NULL) { } } +#' Create ICD 10 diagnoses. + +#' @description +#' ICD-8 is the 8th revision of the International Classification of Diseases. +#' @param n The number of ICD-8 diagnoses to generate. +#' +#' @return n ICD-8 diagnoses as characters. +#' +#' @examples +#' create_fake_icd8(1) create_fake_icd8 <- function(n) { here("data-raw/icd8-codes.csv") |> read_csv() |> @@ -54,6 +85,16 @@ create_fake_icd8 <- function(n) { sample(size = n, replace = TRUE) } +#' Create fake ICD 10 diagnoses. +#' +#' @description +#' ICD-10 is the 10th revision of the International Classification of Diseases. +#' @param n An integer determining how many diagnoses will be created. +#' +#' @return n ICD-10 diagnoses as characters. +#' +#' @examples +#' create_fake_icd10(3) create_fake_icd10 <- function(n) { # from: https://medinfo.dk/sks/brows.php?s_nod=6308 here("data-raw/icd10-codes.csv") |> @@ -62,6 +103,17 @@ create_fake_icd10 <- function(n) { sample(size = n, replace = TRUE) } +#' Create fake ATC codes. +#' +#' @description +#' Anatomical Therapeutic Chemical (ATC) codes are unique medicine codes +#' based on on what organ or system it works on and how it works. +#' @param n The number of fake ATC codes to generate. +#' +#' @return n ATC codes as characters. +#' +#' @examples +#' create_fake_atc(10) create_fake_atc <- function(n) { codeCollection::ATCKoodit |> tibble::as_tibble() |> @@ -70,17 +122,46 @@ create_fake_atc <- function(n) { sample(n, replace = TRUE) } +#' Create fake dates. +#' +#' @param n The number of dates to generate. +#' @param from A date determining the first date in the interval to sample from. +#' @param to A date determining the last date in the interval to sample from. +#' +#' @return n dates. +#' +#' @examples +#' create_fake_date(20) +#' create_fake_date(20, "1995-04-19", "2024-04-19") create_fake_date <- function(n, from = "1977-01-01", to = lubridate::today()) { seq(as_date(from), as_date(to), by = "day") |> sample(n, replace = TRUE) } +#' Create padded integers. +#' +#' @param n The number of integers to generate. +#' @param length An integer determining the length of the padded integer. +#' +#' @return n padded integers as characters. +#' +#' @examples +#' create_padded_integer(5,10) create_padded_integer <- function(n, length) { purrr::map(1:length, \(ignore) sample(0:9, n, replace = TRUE)) |> purrr::reduce(\(integer1, integer2) paste(integer1, integer2, sep = "")) |> pad_integers(width = length) } +# TODO: Add description on what NPU codes are. +#' Create fake NPU codes. +#' +#' @param n The number of NPUs to create. +#' +#' @return n NPUs as characters. +#' +#' @examples +#' create_fake_npu(4) create_fake_npu <- function(n) { stringr::str_c( "NPU", @@ -88,6 +169,14 @@ create_fake_npu <- function(n) { ) } +#' Create department specialties. +#' +#' @param n The number of department specialties to create. +#' +#' @return n random department specialties. +#' +#' @examples +#' create_fake_hovedspeciale_ans(1000) create_fake_hovedspeciale_ans <- function(n) { "https://www.dst.dk/da/Statistik/dokumentation/Times/forebyggelsesregistret/spec" |> read_html() |> @@ -97,6 +186,14 @@ create_fake_hovedspeciale_ans <- function(n) { sample(n, replace = TRUE) } +#' Create drug names based on ATC code. +#' +#' @param atc A character describing an ATC code. +#' +#' @return A character with the drug name of the given ATC code. +#' +#' @examples +#' create_fake_drug_name(c("A03FA05") create_fake_drug_name <- function(atc) { codeCollection::ATCKoodit |> tibble::as_tibble() |> @@ -105,10 +202,28 @@ create_fake_drug_name <- function(atc) { sample(length(atc), replace = TRUE) } +#' Transform date(s) to the format wwyy. +#' +#' @param x A date or a vector of dates. +#' +#' @return The input date(s) in the format wwyy. +#' +#' @examples +#' to_wwyy("2020-12-01") +#' to_wwyy(c("2020-01-12", "1995-04-19")) to_wwyy <- function(x) { paste0(lubridate::isoweek(lubridate::as_date(x)), stringr::str_sub(lubridate::isoyear(lubridate::as_date(x)), -2)) } +#' Transform date(s) to the format yyyymmdd. +#' +#' @param x A date or a vector of dates. +#' +#' @return The input date(s) in the format yyyymmdd. +#' +#' @examples +#' to_yyyymmdd("2020-12-01") +#' to_yyyymmdd(c("2020-01-12", "1995-04-19")) to_yyyymmdd <- function(x) { format(lubridate::as_date(x), format = "%Y%m%d") } From f7f3f55acd4d94ec227e5ff9a20993643ef2ffce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Signe=20Kirk=20Br=C3=B8db=C3=A6k?= Date: Wed, 19 Jun 2024 09:50:00 +0200 Subject: [PATCH 2/6] docs: :memo: add documentation to simulation functions --- data-raw/simulate-data.R | 95 +++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/data-raw/simulate-data.R b/data-raw/simulate-data.R index ab5b3c9..9c4e963 100644 --- a/data-raw/simulate-data.R +++ b/data-raw/simulate-data.R @@ -38,8 +38,8 @@ library(rvest) #' @return A zero padded integer #' #' @examples -#' pad_integers(x=1, width=5) -#' pad_integers(x=c(1,2,3), width=10) +#' pad_integers(x = 1, width = 5) +#' pad_integers(x = c(1, 2, 3), width = 10) pad_integers <- function(x, width) { x |> stringr::str_trunc(width = width, side = "left", ellipsis = "") |> @@ -146,16 +146,18 @@ create_fake_date <- function(n, from = "1977-01-01", to = lubridate::today()) { #' @return n padded integers as characters. #' #' @examples -#' create_padded_integer(5,10) +#' create_padded_integer(5, 10) create_padded_integer <- function(n, length) { purrr::map(1:length, \(ignore) sample(0:9, n, replace = TRUE)) |> purrr::reduce(\(integer1, integer2) paste(integer1, integer2, sep = "")) |> pad_integers(width = length) } -# TODO: Add description on what NPU codes are. #' Create fake NPU codes. #' +#' @description +#' Nomenclature for Properties and Units (NPUs) are codes that identifies +#' laboratory results. #' @param n The number of NPUs to create. #' #' @return n NPUs as characters. @@ -186,14 +188,15 @@ create_fake_hovedspeciale_ans <- function(n) { sample(n, replace = TRUE) } -#' Create drug names based on ATC code. +#' Create drug names from ATC codes. #' #' @param atc A character describing an ATC code. #' #' @return A character with the drug name of the given ATC code. #' #' @examples -#' create_fake_drug_name(c("A03FA05") +#' create_fake_drug_name("A03FA05") +#' create_fake_drug_name(c("A03FA05", "A02BA04")) create_fake_drug_name <- function(atc) { codeCollection::ATCKoodit |> tibble::as_tibble() |> @@ -230,10 +233,28 @@ to_yyyymmdd <- function(x) { # Insert extra values to overrepresent certain values ------------------------------------------------------ +#' Generate logic based on a probability +#' +#' @param proportion A double between 0 and 1. +#' +#' @return A logic. TRUE if the random number is less than the proportion, +#' otherwise FALSE. +#' +#' @examples +#' insertion_rate(0.3) insertion_rate <- function(proportion) { runif(1) < proportion } +#' Insert ATC based on a proportion +#' +#' @param data A tibble +#' @param proportion Proportion to be resampled. Defaults to 0.3. +#' +#' @return A tibble with a proportion of resampled ATC codes for columns +#' named 'atc' +#' +#' @examples insert_specific_atc <- function(data, proportion = 0.3) { glucose_lowering_drugs <- c( metformin = "A10AB02", @@ -264,8 +285,17 @@ insert_specific_atc <- function(data, proportion = 0.3) { ) } -# Insert a few cases where purchases of metformin are used for other purposes -# than diabetes. +#' Insert cases where metformin is used for other purposes than diabetes +#' +#' @description +#' This function uses the variable 'indo' which is the code for the underlying +#' condition treated by the prescribed medication. +#' +#' @param data A tibble +#' @param proportion Proportion to resample. Defaults to 0.05. +#' +#' @return A tibble. If all column names in the tibble is either 'atc' or +#' 'name', a proportion of observations is resampled as metmorfin. insert_false_metformin <- function(data, proportion = 0.05) { if (!all(colnames(data) %in% c("atc", "name"))) { return(data) @@ -285,7 +315,14 @@ insert_false_metformin <- function(data, proportion = 0.05) { ) } -# Insert some false positives for Wegovy and Saxenda. +# Insert false positives for Wegovy and Saxenda. +#' +#' @param data A tibble. +#' @param proportion Proportion to resample. Defaults to 0.05. +#' +#' @return A tibble. If all column names in the tibble is either 'atc' or 'name' +#' and the atc is a A10BJ06 or A10BJ02, a proportion of observations is resampled +#' to have the name Wegovy Flextouch or Saxenda. insert_false_drug_names <- function(data, proportion = 0.05) { if (!all(colnames(data) %in% c("atc", "name"))) { return(data) @@ -300,6 +337,13 @@ insert_false_drug_names <- function(data, proportion = 0.05) { ) } +#' Insert additional analysis codes for HbA1c. +#' +#' @param data A tibble. +#' @param proportion Proportion to resample. Defaults to 0.3. +#' +#' @return A tibble. If a column is named "analysiscode", a proportion of the +#' values are replaced by codes for HbA1c. insert_analysiscode <- function(data, proportion = 0.3) { # NPU27300: New units for HbA1c # NPU03835: Old units for HbA1c @@ -316,11 +360,32 @@ insert_analysiscode <- function(data, proportion = 0.3) { ) } +#' Add drug names (from ATC codes). +#' +#' @param data A tibble. +#' +#' @return A tibble. For columns named "name", a fake drug name (atc) will be +#' added. +add_fake_drug_name <- function(data) { + data |> + mutate( + across( + matches("^name$"), + \(x) create_fake_drug_name(atc = atc) + ) + ) +} + # TODO: Need a function to reuse recnum and dw_ek_kontakt in LPR data # Simulate data ----------------------------------------------------------- -# use the simulation definition data to simulate some data +#' Simulate data based on simulation definitions. +#' +#' @param data A tibble with simulation definitions. +#' @param n Number of observations to simulate. +#' +#' @return A tibble with simulated data. simulate_data <- function(data, n) { # N needs to be capitalized for fabricatr, and but to be consistent # with other functions and their use of `n`, I kept it lowercase for @@ -337,16 +402,6 @@ simulate_data <- function(data, n) { list_cbind() } -add_fake_drug_name <- function(data) { - data |> - mutate( - across( - matches("^name$"), - \(x) create_fake_drug_name(atc = atc) - ) - ) -} - set.seed(123) simulation_definitions <- here("data-raw/simulation-definitions.csv") |> read_csv(show_col_types = FALSE) |> From ea77f9243e4f02c4f9b86d3ea1cb7d89488ce03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Signe=20Kirk=20Br=C3=B8db=C3=A6k?= <40836345+signekb@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:26:51 +0200 Subject: [PATCH 3/6] docs: apply suggestions from code review Co-authored-by: Luke W. Johnston --- data-raw/simulate-data.R | 82 +++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/data-raw/simulate-data.R b/data-raw/simulate-data.R index 9c4e963..87ecfb8 100644 --- a/data-raw/simulate-data.R +++ b/data-raw/simulate-data.R @@ -29,13 +29,13 @@ library(rvest) # Simulation functions ----------------------------------------------------- -#' Zero pad integers +#' Zero pad an integer to a specific length #' -#' @param x An integer or vector of integers -#' @param width An integer describing the final width of the zero-padded integer +#' @param x An integer or vector of integers. +#' @param width An integer describing the final width of the zero-padded integer. #' @keywords internal #' -#' @return A zero padded integer +#' @return A character vector of integers. #' #' @examples #' pad_integers(x = 1, width = 5) @@ -46,16 +46,16 @@ pad_integers <- function(x, width) { stringr::str_pad(width = width, side = "left", pad = "0") } -#' Create ICD diagnoses. +#' Create a vector with random ICD-8 or -10 diagnoses #' -#' @param n The number of ICD-10 diagnoses to generate. -#' @param date A date determining whether the diagnoses should be ICD-8 or ICD-10. If null, a random date will be sampled to determine which ICD revision the diagnosis should be from. +#' @param n The number of ICD-8 or -10 diagnoses to generate. +#' @param date A date determining whether the diagnoses should be ICD-8 or ICD-10. If null, a random date will be sampled to determine which ICD revision the diagnosis should be from. In the Danish registers, ICD-10 is used after 1994. #' -#' @return n ICD-10 diagnoses as characters. +#' @return A character vector of ICD-10 diagnoses. #' #' @examples #' create_fake_icd(10) -#' #' create_fake_icd(5, "1995-04-19") +#' create_fake_icd(5, "1995-04-19") create_fake_icd <- function(n, date = NULL) { if (is.null(date)) { date <- sample(c("1993-01-01", "1995-01-01"), 1) @@ -68,13 +68,14 @@ create_fake_icd <- function(n, date = NULL) { } } -#' Create ICD 10 diagnoses. +#' Create a vector of random ICD-8 diagnoses #' @description #' ICD-8 is the 8th revision of the International Classification of Diseases. +#' #' @param n The number of ICD-8 diagnoses to generate. #' -#' @return n ICD-8 diagnoses as characters. +#' @return A character vector of ICD-8 diagnoses. #' #' @examples #' create_fake_icd8(1) @@ -85,13 +86,14 @@ create_fake_icd8 <- function(n) { sample(size = n, replace = TRUE) } -#' Create fake ICD 10 diagnoses. +#' Create a vector of random ICD-10 diagnoses. #' #' @description #' ICD-10 is the 10th revision of the International Classification of Diseases. -#' @param n An integer determining how many diagnoses will be created. +#' +#' @param n An integer determining how many diagnoses to create. #' -#' @return n ICD-10 diagnoses as characters. +#' @return A character vector of ICD-10 diagnoses. #' #' @examples #' create_fake_icd10(3) @@ -103,14 +105,15 @@ create_fake_icd10 <- function(n) { sample(size = n, replace = TRUE) } -#' Create fake ATC codes. +#' Create a vector with random ATC codes #' #' @description #' Anatomical Therapeutic Chemical (ATC) codes are unique medicine codes #' based on on what organ or system it works on and how it works. -#' @param n The number of fake ATC codes to generate. +#' +#' @param n The number of random ATC codes to generate. #' -#' @return n ATC codes as characters. +#' @return A character vector of ATC codes. #' #' @examples #' create_fake_atc(10) @@ -122,13 +125,13 @@ create_fake_atc <- function(n) { sample(n, replace = TRUE) } -#' Create fake dates. +#' Create fake dates #' #' @param n The number of dates to generate. #' @param from A date determining the first date in the interval to sample from. #' @param to A date determining the last date in the interval to sample from. #' -#' @return n dates. +#' @return A vector of dates. #' #' @examples #' create_fake_date(20) @@ -138,12 +141,12 @@ create_fake_date <- function(n, from = "1977-01-01", to = lubridate::today()) { sample(n, replace = TRUE) } -#' Create padded integers. +#' Create a vector of random zero-padded integers. #' #' @param n The number of integers to generate. #' @param length An integer determining the length of the padded integer. #' -#' @return n padded integers as characters. +#' @return A character vector of integers. #' #' @examples #' create_padded_integer(5, 10) @@ -153,14 +156,15 @@ create_padded_integer <- function(n, length) { pad_integers(width = length) } -#' Create fake NPU codes. +#' Create a vector of random NPU codes #' #' @description #' Nomenclature for Properties and Units (NPUs) are codes that identifies #' laboratory results. +#' #' @param n The number of NPUs to create. #' -#' @return n NPUs as characters. +#' @return A character vector. #' #' @examples #' create_fake_npu(4) @@ -171,11 +175,11 @@ create_fake_npu <- function(n) { ) } -#' Create department specialties. +#' Create a vector of random department specialties #' #' @param n The number of department specialties to create. #' -#' @return n random department specialties. +#' @return A character vector. #' #' @examples #' create_fake_hovedspeciale_ans(1000) @@ -188,11 +192,11 @@ create_fake_hovedspeciale_ans <- function(n) { sample(n, replace = TRUE) } -#' Create drug names from ATC codes. +#' Create a vector of drug names based on a vector of ATC codes #' #' @param atc A character describing an ATC code. #' -#' @return A character with the drug name of the given ATC code. +#' @return A character vector with the drug name of the given ATC code. #' #' @examples #' create_fake_drug_name("A03FA05") @@ -205,11 +209,11 @@ create_fake_drug_name <- function(atc) { sample(length(atc), replace = TRUE) } -#' Transform date(s) to the format wwyy. +#' Transform date(s) to the format wwyy #' #' @param x A date or a vector of dates. #' -#' @return The input date(s) in the format wwyy. +#' @return A vector of dates in the format wwyy. #' #' @examples #' to_wwyy("2020-12-01") @@ -218,11 +222,11 @@ to_wwyy <- function(x) { paste0(lubridate::isoweek(lubridate::as_date(x)), stringr::str_sub(lubridate::isoyear(lubridate::as_date(x)), -2)) } -#' Transform date(s) to the format yyyymmdd. +#' Transform date(s) to the format yyyymmdd #' #' @param x A date or a vector of dates. #' -#' @return The input date(s) in the format yyyymmdd. +#' @return A vector of dates in the format yyyymmdd. #' #' @examples #' to_yyyymmdd("2020-12-01") @@ -237,7 +241,7 @@ to_yyyymmdd <- function(x) { #' #' @param proportion A double between 0 and 1. #' -#' @return A logic. TRUE if the random number is less than the proportion, +#' @return A logic vector. TRUE if the random number is less than the proportion, #' otherwise FALSE. #' #' @examples @@ -246,9 +250,9 @@ insertion_rate <- function(proportion) { runif(1) < proportion } -#' Insert ATC based on a proportion +#' Insert specific ATC codes based on a proportion #' -#' @param data A tibble +#' @param data A tibble. #' @param proportion Proportion to be resampled. Defaults to 0.3. #' #' @return A tibble with a proportion of resampled ATC codes for columns @@ -291,7 +295,7 @@ insert_specific_atc <- function(data, proportion = 0.3) { #' This function uses the variable 'indo' which is the code for the underlying #' condition treated by the prescribed medication. #' -#' @param data A tibble +#' @param data A tibble. #' @param proportion Proportion to resample. Defaults to 0.05. #' #' @return A tibble. If all column names in the tibble is either 'atc' or @@ -315,7 +319,7 @@ insert_false_metformin <- function(data, proportion = 0.05) { ) } -# Insert false positives for Wegovy and Saxenda. +# Insert false positives for Wegovy and Saxenda #' #' @param data A tibble. #' @param proportion Proportion to resample. Defaults to 0.05. @@ -337,7 +341,7 @@ insert_false_drug_names <- function(data, proportion = 0.05) { ) } -#' Insert additional analysis codes for HbA1c. +#' Insert additional analysis codes for HbA1c #' #' @param data A tibble. #' @param proportion Proportion to resample. Defaults to 0.3. @@ -360,7 +364,7 @@ insert_analysiscode <- function(data, proportion = 0.3) { ) } -#' Add drug names (from ATC codes). +#' Add drug names (from ATC codes) #' #' @param data A tibble. #' @@ -380,7 +384,7 @@ add_fake_drug_name <- function(data) { # Simulate data ----------------------------------------------------------- -#' Simulate data based on simulation definitions. +#' Simulate data based on simulation definitions #' #' @param data A tibble with simulation definitions. #' @param n Number of observations to simulate. From 6cade1502adf8a12e8d6775310f127a16763cb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Signe=20Kirk=20Br=C3=B8db=C3=A6k?= Date: Wed, 19 Jun 2024 12:09:56 +0200 Subject: [PATCH 4/6] fix: flip the condition so it's true when both "atc" and "name" is in data --- data-raw/simulate-data.R | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/data-raw/simulate-data.R b/data-raw/simulate-data.R index 87ecfb8..ff9b7ad 100644 --- a/data-raw/simulate-data.R +++ b/data-raw/simulate-data.R @@ -301,22 +301,23 @@ insert_specific_atc <- function(data, proportion = 0.3) { #' @return A tibble. If all column names in the tibble is either 'atc' or #' 'name', a proportion of observations is resampled as metmorfin. insert_false_metformin <- function(data, proportion = 0.05) { - if (!all(colnames(data) %in% c("atc", "name"))) { - return(data) - } - data |> - dplyr::mutate( - atc = dplyr::if_else( - indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion), - "A10BA02", - atc - ), - name = dplyr::if_else( - indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion), - "metformin", - name + if (all(c("atc", "name") %in% colnames(data))) { + data |> + dplyr::mutate( + atc = dplyr::if_else( + indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion), + "A10BA02", + atc + ), + name = dplyr::if_else( + indo %in% c("0000092", "0000276", "0000781") & insertion_rate(proportion), + "metformin", + name + ) ) - ) + } else { + return(data) + } } # Insert false positives for Wegovy and Saxenda @@ -328,17 +329,18 @@ insert_false_metformin <- function(data, proportion = 0.05) { #' and the atc is a A10BJ06 or A10BJ02, a proportion of observations is resampled #' to have the name Wegovy Flextouch or Saxenda. insert_false_drug_names <- function(data, proportion = 0.05) { - if (!all(colnames(data) %in% c("atc", "name"))) { + if (all(c("atc", "name") %in% colnames(data))) { + data |> + mutate( + name = case_when( + atc == "A10BJ06" & insertion_rate(proportion) ~ "Wegovy Flextouch", + atc == "A10BJ02" & insertion_rate(proportion) ~ "Saxenda", + TRUE ~ name + ) + ) + } else { return(data) } - data |> - mutate( - name = case_when( - atc == "A10BJ06" & insertion_rate(proportion) ~ "Wegovy Flextouch", - atc == "A10BJ02" & insertion_rate(proportion) ~ "Saxenda", - TRUE ~ name - ) - ) } #' Insert additional analysis codes for HbA1c From 17f4d67ca9f0248b84ca5891d5b36be9fef772c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Signe=20Kirk=20Br=C3=B8db=C3=A6k?= Date: Wed, 19 Jun 2024 12:16:34 +0200 Subject: [PATCH 5/6] fix: add "indo" to condition since it's used in the function --- data-raw/simulate-data.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data-raw/simulate-data.R b/data-raw/simulate-data.R index ff9b7ad..bd78571 100644 --- a/data-raw/simulate-data.R +++ b/data-raw/simulate-data.R @@ -301,7 +301,7 @@ insert_specific_atc <- function(data, proportion = 0.3) { #' @return A tibble. If all column names in the tibble is either 'atc' or #' 'name', a proportion of observations is resampled as metmorfin. insert_false_metformin <- function(data, proportion = 0.05) { - if (all(c("atc", "name") %in% colnames(data))) { + if (all(c("atc", "name", "indo") %in% colnames(data))) { data |> dplyr::mutate( atc = dplyr::if_else( From 8a2f96613efa57b97a6a9e590770e5be06716c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Signe=20Kirk=20Br=C3=B8db=C3=A6k?= <40836345+signekb@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:18:53 +0200 Subject: [PATCH 6/6] fix: remove return since it's not needed Co-authored-by: Luke W. Johnston --- data-raw/simulate-data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data-raw/simulate-data.R b/data-raw/simulate-data.R index bd78571..5235416 100644 --- a/data-raw/simulate-data.R +++ b/data-raw/simulate-data.R @@ -316,7 +316,7 @@ insert_false_metformin <- function(data, proportion = 0.05) { ) ) } else { - return(data) + data } } @@ -339,7 +339,7 @@ insert_false_drug_names <- function(data, proportion = 0.05) { ) ) } else { - return(data) + data } }