From 83356e8f25cc5e71c88eda1f2a227a81da2ececa Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:43:53 +0200 Subject: [PATCH 1/9] chore: add logic for filtering GLD in algorithm --- data-raw/algorithm.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/data-raw/algorithm.csv b/data-raw/algorithm.csv index fa6cebc..dd9060e 100644 --- a/data-raw/algorithm.csv +++ b/data-raw/algorithm.csv @@ -1,3 +1,4 @@ name,logic hba1c,(analysiscode == 'NPU27300' AND value >= 48) OR (analysiscode == 'NPU03835' AND value >= 6.5) +gld,atc =~ '^A10' From 6a05948b10c432ed39bdf0e453b639df4360f709 Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:45:34 +0200 Subject: [PATCH 2/9] build: re-ran targets pipeline to get algorithm updated --- R/sysdata.rda | Bin 1758 -> 1796 bytes _targets/meta/meta | 23 +++++++++++++---------- data/algorithm.rda | Bin 376 -> 397 bytes data/variable_description.rda | Bin 1550 -> 1546 bytes 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/R/sysdata.rda b/R/sysdata.rda index e04eb6cd8b71a9ca92e2ac62e088826a9a88ff80..99e839d77e36a931474a652f8288f9cadcd55dcf 100644 GIT binary patch literal 1796 zcmV+f2mAO!T4*^jL0KkKS+Ofih5!aJfA|0Y|JQf#|HJGB-b26d-{HVS00EEyKmY&` z1OPw*;0NCNkD<{B0001V0ANWdDt=80Jx@a z01XC)gFptE28KY>KmZ0n20&y0H~<G7SuYrhotpfDC}h07Wtg0000000000 z000000ktI6GHpkw4H^$f&>8>$27mwn003xc2@(@T(WXF5iHV4rsginw5Df-^$QlQv zJg1cO)bdYKkR$D1(nT4h0QYSNQAH90OW=&Agb`^F%#^qQ6$z!bOOTw(06eKA2%O<5 zBqoH9cbUP^!Tj|4hdH`gD7^n;h7ls2fdxpXCm>R9WOd2JV0%nbKx$@9Ii72L^Z=rA zp&t}c^W$&2bwC#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ka2gRJZH)w%KS*viVPnKx7aIi-4-L~C z9a<1vT($ww_e0xNxdBy*C5paDbc$q~w_zkJ0b&@tPT*1`R0{`?Ns|RKc#p=&3}d{a zS*`u2mv*|BGVwH&5QfrQ`YFg*nhGS1JW*SaP)!U$1Rx;JFsZSy=;cJY0^qqgq8M~m z_EQ+hMnIhgPf7!kN+ysJJU$R69W_pj6u$1Oc`J}D3+wC83(yABoqy>bC4Rk>B?LsNXQu1-X=m) z6A8zN}`DjM!_!n77PH)f~abKATl*#mZX=5 znfW}0DE+ToBYpsG&rzT=3N1l#tKUAC051So7lr{7&~U`tM7j64L6b_#>YGWI6o$x& z)K3)E6a(x{I*>60g>wUu;B37u8C*f2CvYJ0ns+5~pdx@s%}Q+wgEDBK?-LDo1}P{I zVjA#C@0z?~Qc}jptkjHgCX%xf)M-lq^k_JKA8Wq4#Ri@nCA|9|!1WjH4zwGCAg7uR z!JjxBM64?p14r#bJ!E~F=T%*l2dtyCHq)$ diff --git a/_targets/meta/meta b/_targets/meta/meta index 54603f2..ca5160a 100644 --- a/_targets/meta/meta +++ b/_targets/meta/meta @@ -1,25 +1,28 @@ name|type|data|command|depend|seed|path|time|size|bytes|format|repository|iteration|parent|children|seconds|warnings|error .__global__|object|87b8d4f266c27bf4||||||||||||||| -algorithm|stem|10ca7cf5842c7665|e6ba0f398c6f1faa|60a40402a9fb99aa|-536052671||t19899.4087817699s|9fa82258c19da069|337|rds|local|vector|||0.001|| -algorithm_csv|stem|98f92607dd48318b|72b6696561a29259|2c530c1562a7fbd1|48686226|data-raw/algorithm.csv|t19893.5100784042s|530f140998b50d1c|112|file|local|vector|||0.003|| -algorithm_rda|stem|66f7362503371611|07904a5fa14d0614|9fd483aca6d9122e|-930623318|/home/luke/Documents/organizations/steno-aarhus/osdc/data/algorithm.rda|t19899.4272374029s|a96add13dbb67aa3|376|file|local|vector|||0.01|| +algorithm|stem|40723e52fd2c0786|e6ba0f398c6f1faa|396a620bf28c517b|-536052671||t19984.6357532965s|cfeff01d1edd45fa|355|rds|local|vector|||0.003|| +algorithm_csv|stem|499e7e860784d28e|72b6696561a29259|2c530c1562a7fbd1|48686226|data-raw/algorithm.csv|t19984.6344032286s|06ecd420619ded44|130|file|local|vector|||0.005|| +algorithm_rda|stem|10280eb55316ebbd|07904a5fa14d0614|b947939e3d638088|-930623318|/home/luke/Documents/steno-aarhus/osdc/data/algorithm.rda|t19984.6357559003s|06569f4b2b5547d7|397|file|local|vector|||0.064|| column_names_to_lower|function|1f9ed89ec76f0ce4||||||||||||||| create_algorithm_data|function|721802c40fcbce4e||||||||||||||| create_variable_description_data|function|ede086e002225ffb||||||||||||||| -get_algorithm_logic|function|87ff06f2c9ce0900||||||||||||||| +get_algorithm_logic|function|0f0fdebe7fb843f9||||||||||||||| get_register_abbrev|function|a82c561691b651df||||||||||||||| get_required_variables|function|986ccd76798db1ba||||||||||||||| -include_hba1c|function|e0b1243dd274269a||||||||||||||| -internal_rda|stem|7d593b3244eb6fb5|76d906cefcbfa41d|cbd1dbe82f00b76b|765355582|/home/luke/Documents/organizations/steno-aarhus/osdc/R/sysdata.rda|t19899.427237588s|f58dd1a2582f84fa|1758|file|local|vector|||0.008|| +include_gld_purchases|function|5c4b4af47e61ff3e||||||||||||||| +include_hba1c|function|56a5b4012c489ff5||||||||||||||| +internal_rda|stem|4cefbc8d2053be42|76d906cefcbfa41d|63728ca9f77d87ee|765355582|/home/luke/Documents/steno-aarhus/osdc/R/sysdata.rda|t19984.6357562591s|5fd1d38a27b446ca|1796|file|local|vector|||0.026|| +join_lpr2|function|73dfa05a6f146f76||||||||||||||| +join_lpr3|function|1690200e83e2d60d||||||||||||||| read_algorithm_data|function|ef107d4466f53ae2||||||||||||||| read_variable_description_data|function|bac5d03645e8328d||||||||||||||| register_as_md_header|function|1b9b0bb62cc1e264||||||||||||||| register_data_as_md_table|function|bbdda3785a7bdb63||||||||||||||| registers_as_md_table|function|ab56ce7262ba313b||||||||||||||| -variable_description|stem|6d3dd1f2baa26b82|c2153d67e5651737|a01d9e94aead7bb8|1287048845||t19899.4087817236s|b9834ab70a709536|1311|rds|local|vector|||0.133|| -variable_description_csv|stem|900853341b756f57|2347307fa16d111b|2c530c1562a7fbd1|113481566|data-raw/variable-description.csv|t19845.4834059685s|75bbd1de9a7a9806|4683|file|local|vector|||0.005|| -variable_description_rda|stem|450aefe34ecbfb32|afe48e93eb17b9c8|92ce3d1b47fe163e|-1262878967|/home/luke/Documents/organizations/steno-aarhus/osdc/data/variable_description.rda|t19899.427237264s|5272409a13fc9df9|1550|file|local|vector|||0.058|| +variable_description|stem|1d60446ae54d3249|c2153d67e5651737|a01d9e94aead7bb8|1287048845||t19984.6357532155s|c5e2c6b0e4727be8|1313|rds|local|vector|||0.201|| +variable_description_csv|stem|900853341b756f57|2347307fa16d111b|2c530c1562a7fbd1|113481566|data-raw/variable-description.csv|t19899.5887162511s|75bbd1de9a7a9806|4683|file|local|vector|||0.005|| +variable_description_rda|stem|912e95a27b0cc7a1|afe48e93eb17b9c8|810d0414c7e649b1|-1262878967|/home/luke/Documents/steno-aarhus/osdc/data/variable_description.rda|t19984.6357551018s|8e5879d34632f507|1546|file|local|vector|||0.153|| variables_as_md_table|function|bf10d1f0df6a170a||||||||||||||| -verify_required_variables|function|52bf07b827f57531||||||||||||||| +verify_required_variables|function|070c8fb3014efb9e||||||||||||||| write_external_rda|function|c0c90c7048a0d89b||||||||||||||| write_internal_rda|function|95b61d841de16e96||||||||||||||| diff --git a/data/algorithm.rda b/data/algorithm.rda index e0177895ad9fa562a56bfd5f39a7e53e828b5292..9f8da15808b52f7e6013bcdb92478e226f704588 100644 GIT binary patch literal 397 zcmV;80doFAT4*^jL0KkKSy-{{1^@vf|G@wH$pAp*f5RjJ(nG)J-=RPN00FQ8RxzNI zNvOp(O;12f$^dDQ(=`uC>8X+Ao=|9}6!koj>Hq)$0000D0z{^vGI~QshM6?T#L1%w z!e|;A2b0o9WaI=9LZXtCs2d<4L$Qdz1U3i{X@vwIiTm|T-81`yNS&$Vd(x31#E7*W zRANFXgAkQ=fONJ~ph)_Pq|`W}J_0^0b?*e|8xTx{nm{&ziHuB28U#azlNgY-cEANt zlCd?G&cY%!F_3$jje0}rlVaOVn_ruL>$#ks^S9plWRtfkxVVKXP)W{a8q@fgl|I$0H8!A_QaXuNCij1lh36lT`guyU|0E_@6P)d4geyQa&G&E=f zKmceOWDPD?NNu$A;z1Oewo;qXdMHL`qRIHVw$#Wx_%c-%>oi)BUuum~XU%eu;NeOsO1|W(;Xh>pX69on$4GBS{#t2z4!6iVGg6urm z2x=tSc>3#07gT=M;g+jeoprY)4{coavQyx6O9|{J7{lvTrBrCrX%w$5dze#!c;bU` zz-`+c%$#oHNTptHthzMbUuMCgQ3=8L3sOS^1eiw!N;*2h`d=Pyf%`v+;4yEj)yz@W zq{U$EkZxguDrN&#x=^6NxJa22bVQH}NDh_fq0#A~TxKNFV+(Sx^B1KvC`^Qpd6(p8 W#)J0`qZ@%A@pmLsg$W8r=womXim2`Y diff --git a/data/variable_description.rda b/data/variable_description.rda index 00d3472f5a9ee1d5f6c54ff77612d9eb157de5ea..5885c2b5751a25161acf8c78d4f858711ae5f0d3 100644 GIT binary patch delta 1490 zcmV;@1ugoH42ld6LRx4!F+o`-Q(35<(fN@MCm;CP3I#L(8YlvzgCNnM44PsZXfg~# z2pR)MCL=%q2a!D~e+@K7q9#K_O%G52000Jn004TL4FE+VLn3)iMrl1qrceL?06jnk zji~hxP|50Pw1HAY5GEr{G(#XwPY}{%85$Y}jRr$Zhm_ibg-3wu@Q$2p)`?|Z*GSu2 zlunA2Zv+548(o}IZ^ppzVPw3CQ4g+@=%lk(*X``fBq2&;ebRCYnDRcA3GnRwf(Are7RrD;Td7!5cW$h4~}W!QU_ zA|9ebQ3$Fce?UVh1x8S)A-$SPGlg7G0jMDctNQBJm&;8Yaswe{xjdqTlm-l6ef)Py z%ga-XRGT~dt-XSB#L+E;_AxQlvdSq<4HVAywJApS3fbe)ikVr4o8i&B3~-Z0nVRIq zsj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`FxMwQ5GfS;C!c4T`N`L8GQ`aEAVMK^d2CL2; z%^?R+Bng0!m^BOnXi!zV%QB3iR~`T<2tludfUWvqm&$ua9cER9&`l7-KA%tf<$iW_Uv7VF}-RlIfxYjXjT2dtU%ZRtm8%aneD%|-GZr^pvw z@fX@w^VVKMJ*NXeNIk4b^c+H@jA#}V6avIc?%`Qp8h?x61oVEBK_Cf_R3!~B&F~{j z7sg|gKf^9IB(&Bo_ zTRq2j7_EpU*EC7Z(bgGRNbYeAW8v>b<86$oB7+MRxn>-2n*_x`Flk_MRbg22`A*Su z0>BV%I2f$Hju#0T6k^;kHNY7jYIvFTx{O>6;D3#KF*sqS*9GAJX^ZOs6;KHd89HJsIN|69&SDN}(@_x3g)? zbSV#5Ky#V^FEIf9K^)Bpkv7JHUE#RdeNMu`VYRzx@HluC#mi_OfcKS<6ERl7T_jH= z-Fe9&R0=~5gQOIR6#~KH5@f+lz^8?f7=Onih}FBG@%(zKT+77LP(m9?Z|qZ$u{0D( z8hMdhkWftwK?EQm;$)HR^{)=bi!iX3t?dVeEH);ZY;A+=8M8_POJ31;3|1@wBLOQG z4zQ?o8UkQU1yU8QVVrOnGGL)xae;9Crjk&GLfW}{67nUZH8M4}F|1%0P|!n2XMYkD z5E4p5N$0?qG=jAc2@np&{$t?}e_m;6NxVanX&7Q)Vu3M;I;KRymIE~zB|z4^wgN#w z-3KWplb-hxkTI`eG7^xOPFg&DcwiBr&l7CY>g3@D zww0DOHxn)?4UrS79x19Q2hf^zAYus$<_8}Y$z!U-jQ0V+O2V;lHTEGNVGlLUg?tbll^S0tUnLuai2sYZBAh5lH44g|0L4LpGynhq From 337f5a198b1a6317ed4dc7927cb0e84a0dbfc23a Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:45:59 +0200 Subject: [PATCH 3/9] refactor: add string replacement for regex in algorithm --- R/get-algorithm.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/get-algorithm.R b/R/get-algorithm.R index 93fcf25..0120012 100644 --- a/R/get-algorithm.R +++ b/R/get-algorithm.R @@ -8,11 +8,14 @@ #' @examples #' \dontrun{ #' get_algorithm_logic("hba1c") +#' get_algorithm_logic("gld") #' } get_algorithm_logic <- function(criteria) { algorithm |> dplyr::filter(.data$name == criteria) |> dplyr::pull(.data$logic) |> stringr::str_replace_all("AND", "&") |> - stringr::str_replace_all("OR", "|") + stringr::str_replace_all("OR", "|") |> + # regex are defined with '=~', so convert them into a stringr function. + stringr::str_replace_all("(.*) \\=\\~ (.*)", "stringr::str_detect(\\1, \\2)") } From 3c7149bb2e9e3bda71cfd0a7bd3a4af4a4f6eb66 Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:46:43 +0200 Subject: [PATCH 4/9] feat: :sparkles: add `include_gld_purchases()` --- R/include-gld-purchases.R | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 R/include-gld-purchases.R diff --git a/R/include-gld-purchases.R b/R/include-gld-purchases.R new file mode 100644 index 0000000..c2c6f49 --- /dev/null +++ b/R/include-gld-purchases.R @@ -0,0 +1,39 @@ +#' Include only those who have a purchase of a glucose lowering drug (GLD). +#' +#' See [algorithm] for the logic used to filter these patients. +#' +#' @return The same type as the input data, default as a [tibble::tibble()]. +#' @keywords internal +#' +#' @examples +#' \dontrun{ +#' register_data$lmdb |> include_gld_purchases() +#' } +include_gld_purchases <- function(data) { + verify_required_variables(data, "lmdb") + criteria <- get_algorithm_logic("gld") |> + # To convert the string into an R expression. + rlang::parse_expr() + data |> + column_names_to_lower() |> + # Use !! to inject the expression into filter. + dplyr::filter(!!criteria) |> + # Keep only the columns we need. + dplyr::select( + "pnr", + # Change to date to work with later functions. + date = "eksd", + "atc", + "volume", + "apk", + "indo", + "name", + "vnr" + ) |> + # TODO: Need to add this column? We did for hba1c. + # dplyr::mutate( + # included_gld = TRUE + # ) |> + # Remove any duplicates + dplyr::distinct() +} From 80c8c72c5dbaed56f81dc29d621ed4991c47d7e2 Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:47:04 +0200 Subject: [PATCH 5/9] refactor: small edit to match the gld function --- R/include-hba1c.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/include-hba1c.R b/R/include-hba1c.R index 3180e7b..802acc1 100644 --- a/R/include-hba1c.R +++ b/R/include-hba1c.R @@ -15,13 +15,13 @@ #' } include_hba1c <- function(data) { verify_required_variables(data, "lab_forsker") - hba1c_criteria <- get_algorithm_logic("hba1c") |> + criteria <- get_algorithm_logic("hba1c") |> # To convert the string into an R expression. rlang::parse_expr() data |> column_names_to_lower() |> # Use !! to inject the expression into filter. - dplyr::filter(!!hba1c_criteria) |> + dplyr::filter(!!criteria) |> # Keep only the columns we need. dplyr::mutate( pnr = .data$patient_cpr, From d6715b153360c6a17ea69f4df178eaee345ef731 Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:47:21 +0200 Subject: [PATCH 6/9] docs: generated the roxygen docs --- man/get_algorithm_logic.Rd | 1 + man/include_gld_purchases.Rd | 20 ++++++++++++++++++++ man/osdc-package.Rd | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 man/include_gld_purchases.Rd diff --git a/man/get_algorithm_logic.Rd b/man/get_algorithm_logic.Rd index 59c4486..b7ba8a7 100644 --- a/man/get_algorithm_logic.Rd +++ b/man/get_algorithm_logic.Rd @@ -18,6 +18,7 @@ Get the criteria algorithmic logic and convert to an R logic condition. \examples{ \dontrun{ get_algorithm_logic("hba1c") +get_algorithm_logic("gld") } } \keyword{internal} diff --git a/man/include_gld_purchases.Rd b/man/include_gld_purchases.Rd new file mode 100644 index 0000000..b89bbfa --- /dev/null +++ b/man/include_gld_purchases.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/include-gld-purchases.R +\name{include_gld_purchases} +\alias{include_gld_purchases} +\title{Include only those who have a purchase of a glucose lowering drug (GLD).} +\usage{ +include_gld_purchases(data) +} +\value{ +The same type as the input data, default as a \code{\link[tibble:tibble]{tibble::tibble()}}. +} +\description{ +See \link{algorithm} for the logic used to filter these patients. +} +\examples{ +\dontrun{ +register_data$lmdb |> include_gld_purchases() +} +} +\keyword{internal} diff --git a/man/osdc-package.Rd b/man/osdc-package.Rd index 6c8a49c..8c30eb9 100644 --- a/man/osdc-package.Rd +++ b/man/osdc-package.Rd @@ -6,6 +6,8 @@ \alias{osdc-package} \title{osdc: Open Source Diabetes Classifier (OSDC) for Danish Registers} \description{ +\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} + This classifier first identifies a population of individuals with any type of diabetes mellitus and then splits this population into T1D and T2D by identifying individuals with T1D and classifying the remainder of the diabetes population as T2D. } \seealso{ From 2d260293a286a9c55a9064b8758aff937b360070 Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Wed, 18 Sep 2024 17:47:31 +0200 Subject: [PATCH 7/9] tests: add tests for GLD purchases --- tests/testthat/test-include-gld-purchases.R | 102 ++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/testthat/test-include-gld-purchases.R diff --git a/tests/testthat/test-include-gld-purchases.R b/tests/testthat/test-include-gld-purchases.R new file mode 100644 index 0000000..354302b --- /dev/null +++ b/tests/testthat/test-include-gld-purchases.R @@ -0,0 +1,102 @@ +constants <- tibble::tibble( + pnr = "2132131231", + eksd = "20210101", + volume = 1.1, + apk = 1.1, + indo = "324314324", + name = "random", + vnr = "123123" +) + +lmdb <- tibble::tribble( + ~atc, + "A10abc", + "A10", + "A10123", + "A11", + "A21", + "B10A10", +) |> + dplyr::bind_cols(constants) + +expected <- tibble::tribble( + ~atc, + "A10abc", + "A10", + "A10123", +) |> + dplyr::bind_cols(constants) |> + dplyr::rename(date = eksd) |> + dplyr::relocate(atc, .after = date) + +test_that("dataset needs expected variables", { + actual <- lmdb[-2] + expect_error(include_gld_purchases(actual)) +}) + +test_that("those with inclusion are kept", { + actual <- include_gld_purchases(lmdb) + expect_equal(actual, expected) +}) + +test_that("casing of input variables doesn't matter", { + actual <- lmdb |> + dplyr::rename_with(\(columns) toupper(columns)) |> + include_gld_purchases() + expect_equal(actual, expected) +}) + +test_that("verification works for DuckDB Database", { + skip_on_cran() + skip_if_not_installed("duckplyr") + actual <- duckplyr::as_duckplyr_tibble(lmdb) |> + include_gld_purchases() + + actual_rows <- actual |> + dplyr::count() |> + dplyr::pull(n) + + expect_equal(actual_rows, nrow(expected)) + expect_equal(colnames(actual), colnames(expected)) +}) + +test_that("verification works for Arrow Tables (from Parquet)", { + skip_on_cran() + skip_if_not_installed("arrow") + actual <- arrow::as_arrow_table(lmdb) |> + include_gld_purchases() + + actual_rows <- actual |> + dplyr::count() |> + dplyr::pull(n) + + expect_equal(actual_rows, nrow(expected)) + # TODO: Arrow doesn't work with colname(), fix? + expect_equal(names(actual), colnames(expected)) +}) + +test_that("verification works for data.frame", { + actual <- as.data.frame(lmdb) |> + include_gld_purchases() + + actual_rows <- actual |> + dplyr::count() |> + dplyr::pull(n) + + expect_equal(actual_rows, nrow(expected)) + expect_equal(colnames(actual), colnames(expected)) +}) + +test_that("verification works for data.table", { + skip_on_cran() + skip_if_not_installed("data.table") + actual <- data.table::as.data.table(lmdb) |> + include_gld_purchases() + + actual_rows <- actual |> + dplyr::count() |> + dplyr::pull(n) + + expect_equal(actual_rows, nrow(expected)) + expect_equal(colnames(actual), colnames(expected)) +}) From 96d5d469e15d3eb484b8946469b92a89dd3afef4 Mon Sep 17 00:00:00 2001 From: Anders Aasted Isaksen <67263135+Aastedet@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:43:56 +0200 Subject: [PATCH 8/9] remove unnecessary column and duplication in include_gld_purchases Co-authored-by: Luke W. Johnston --- R/include-gld-purchases.R | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/R/include-gld-purchases.R b/R/include-gld-purchases.R index c2c6f49..0d1e068 100644 --- a/R/include-gld-purchases.R +++ b/R/include-gld-purchases.R @@ -29,11 +29,5 @@ include_gld_purchases <- function(data) { "indo", "name", "vnr" - ) |> - # TODO: Need to add this column? We did for hba1c. - # dplyr::mutate( - # included_gld = TRUE - # ) |> - # Remove any duplicates - dplyr::distinct() + ) } From 875cfcddd2dfaefdf115fcbb7271c8c8771854ef Mon Sep 17 00:00:00 2001 From: "Luke W. Johnston" Date: Thu, 19 Sep 2024 15:23:35 +0200 Subject: [PATCH 9/9] refactor: :recycle: to match arg style of other functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Signe Kirk Brødbæk <40836345+signekb@users.noreply.github.com> --- R/include-gld-purchases.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/include-gld-purchases.R b/R/include-gld-purchases.R index 0d1e068..e37b19d 100644 --- a/R/include-gld-purchases.R +++ b/R/include-gld-purchases.R @@ -9,12 +9,12 @@ #' \dontrun{ #' register_data$lmdb |> include_gld_purchases() #' } -include_gld_purchases <- function(data) { - verify_required_variables(data, "lmdb") +include_gld_purchases <- function(lmdb) { + verify_required_variables(lmdb, "lmdb") criteria <- get_algorithm_logic("gld") |> # To convert the string into an R expression. rlang::parse_expr() - data |> + lmdb |> column_names_to_lower() |> # Use !! to inject the expression into filter. dplyr::filter(!!criteria) |>