From 9cd914a97f8e05390a163811b9856c34ade6cf0c Mon Sep 17 00:00:00 2001 From: Peter Dutey-Magni Date: Sun, 19 Nov 2023 11:31:33 +0000 Subject: [PATCH] upgrade to dbplyr 2.4.0 and change unit tests of remote tables for Ramses objects --- DESCRIPTION | 9 ++- NEWS.md | 9 +++ tests/testthat/test-objects.R | 144 +++++++++++++--------------------- 3 files changed, 69 insertions(+), 93 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1d6ef1d..7d81fa1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: Ramses Type: Package Title: R Package for Antimicrobial Stewardship & Surveillance -Version: 0.7.0 +Version: 0.7.1 Authors@R: c( person(given = "Peter", family = "Dutey-Magni", @@ -31,7 +31,7 @@ Imports: DBI, rlang, dplyr (>= 1.1.0), - dbplyr (>= 2.3.2), + dbplyr (>= 2.4.0), tidyselect (>= 1.2.0), magrittr, duckdb (>= 0.4.0), @@ -59,11 +59,12 @@ Suggests: R.utils, comorbidity, RPostgres, - gh (>= 1.3.0) + gh (>= 1.3.0), + vctrs Remotes: ramses-antibiotics/snomedizer RdMacros: Rdpack -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 VignetteBuilder: knitr,rmarkdown Collate: 'Ramses-deprecated.R' diff --git a/NEWS.md b/NEWS.md index 1929f14..c8c6095 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,13 @@ +# Ramses 0.7.1 + +*19 November 2023* + +## Changed + +- Now requires minimum `dbplyr` v2.4.0. +- Unit test maintenance required by `dbplyr` v2.4.0. + # Ramses 0.7.0 *11 April 2023* diff --git a/tests/testthat/test-objects.R b/tests/testthat/test-objects.R index 8467bf7..877ba32 100644 --- a/tests/testthat/test-objects.R +++ b/tests/testthat/test-objects.R @@ -68,16 +68,14 @@ test_that("Patient..interface_methods DuckDB", { expect_equal(capture.output(patient_object)[1], "Patient 99999999999 ") # COMPUTE - expect_equal( - patient_object@record$lazy_query$x$x, - structure("patients", class = c("ident", "character")) - ) + expect_is(patient_object@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(patient_object@record$lazy_query$x$x, "table"), "patients") + patient_object_computed <- compute(patient_object) + expect_true( grepl("^dbplyr_", - as.character( - patient_object_computed@record$lazy_query$x - )) + vctrs::field(patient_object_computed@record$lazy_query$x, "table")) ) # COLLECT @@ -119,16 +117,14 @@ test_that("Patient..interface_methods Postgres", { expect_equal(capture.output(patient_object)[1], "Patient 99999999999 ") # COMPUTE - expect_equal( - patient_object@record$lazy_query$x$x, - structure("patients", class = c("ident", "character")) - ) + expect_is(patient_object@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(patient_object@record$lazy_query$x$x, "table"), "patients") + patient_object_computed <- compute(patient_object) + expect_true( grepl("^dbplyr_", - as.character( - patient_object_computed@record$lazy_query$x - )) + vctrs::field(patient_object_computed@record$lazy_query$x, "table")) ) # COLLECT @@ -278,16 +274,16 @@ test_that("MedicationRequest..interface_methods DuckDB", { ) # COMPUTE + expect_is(med_req_object@record$lazy_query$x$x, "dbplyr_table_ident") expect_equal( - med_req_object@record$lazy_query$x$x, - structure("drug_prescriptions", class = c("ident", "character")) + vctrs::field(med_req_object@record$lazy_query$x$x, "table"), + "drug_prescriptions" ) + med_req_object_computed <- compute(med_req_object) expect_true( grepl("^dbplyr_", - as.character( - med_req_object_computed@record$lazy_query$x - )) + vctrs::field(med_req_object_computed@record$lazy_query$x, "table")) ) # COLLECT @@ -381,16 +377,13 @@ test_that("MedicationRequest..interface_methods Postgres", { ) # COMPUTE - expect_equal( - med_req_object@record$lazy_query$x$x, - structure("drug_prescriptions", class = c("ident", "character")) - ) + expect_is(med_req_object@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(med_req_object@record$lazy_query$x$x, "table"), "drug_prescriptions") + med_req_object_computed <- compute(med_req_object) expect_true( grepl("^dbplyr_", - as.character( - med_req_object_computed@record$lazy_query$x - )) + vctrs::field(med_req_object_computed@record$lazy_query$x, "table")) ) # COLLECT @@ -533,38 +526,31 @@ test_that("TherapyEpisode..interface_methods DuckDB", { ) # COMPUTE - expect_equal( - therapy_object@record$lazy_query$x$x, - structure("drug_therapy_episodes", class = c("ident", "character")) - ) + expect_is(therapy_object@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(therapy_object@record$lazy_query$x$x, "table"), + "drug_therapy_episodes") therapy_object_computed <- compute(therapy_object) expect_true( grepl("^dbplyr_", - as.character( - therapy_object_computed@record$lazy_query$x - )) - ) - expect_equal( - therapy_object_multi@record$lazy_query$x$x, - structure("drug_therapy_episodes", class = c("ident", "character")) + vctrs::field(therapy_object_computed@record$lazy_query$x, "table")) ) + + expect_is(therapy_object_multi@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(therapy_object_multi@record$lazy_query$x$x, "table"), + "drug_therapy_episodes") therapy_object_multi_computed <- compute(therapy_object_multi) expect_true( grepl("^dbplyr_", - as.character( - therapy_object_multi_computed@record$lazy_query$x - )) - ) - expect_equal( - therapy_object_multi4@record$lazy_query$x$x, - structure("drug_therapy_episodes", class = c("ident", "character")) + vctrs::field(therapy_object_multi_computed@record$lazy_query$x, "table")) ) + + expect_is(therapy_object_multi4@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(therapy_object_multi4@record$lazy_query$x$x, "table"), + "drug_therapy_episodes") therapy_object_multi_computed4 <- compute(therapy_object_multi4) expect_true( grepl("^dbplyr_", - as.character( - therapy_object_multi_computed4@record$lazy_query$x - )) + vctrs::field(therapy_object_multi_computed4@record$lazy_query$x, "table")) ) # COLLECT @@ -699,38 +685,28 @@ test_that("TherapyEpisode..interface_methods Postgres", { ) # COMPUTE - expect_equal( - therapy_object@record$lazy_query$x$x, - structure("drug_therapy_episodes", class = c("ident", "character")) - ) + expect_is(therapy_object@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(therapy_object@record$lazy_query$x$x, "table"), "drug_therapy_episodes") therapy_object_computed <- compute(therapy_object) expect_true( grepl("^dbplyr_", - as.character( - therapy_object_computed@record$lazy_query$x - )) - ) - expect_equal( - therapy_object_multi@record$lazy_query$x$x, - structure("drug_therapy_episodes", class = c("ident", "character")) + vctrs::field(therapy_object_computed@record$lazy_query$x, "table")) ) + + expect_is(therapy_object_multi@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(therapy_object_multi@record$lazy_query$x$x, "table"), "drug_therapy_episodes") therapy_object_multi_computed <- compute(therapy_object_multi) expect_true( grepl("^dbplyr_", - as.character( - therapy_object_multi_computed@record$lazy_query$x - )) - ) - expect_equal( - therapy_object_multi4@record$lazy_query$x$x, - structure("drug_therapy_episodes", class = c("ident", "character")) + vctrs::field(therapy_object_multi_computed@record$lazy_query$x, "table")) ) + + expect_is(therapy_object_multi4@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(therapy_object_multi4@record$lazy_query$x$x, "table"), "drug_therapy_episodes") therapy_object_multi_computed4 <- compute(therapy_object_multi4) expect_true( grepl("^dbplyr_", - as.character( - therapy_object_multi_computed4@record$lazy_query$x - )) + vctrs::field(therapy_object_multi_computed4@record$lazy_query$x, "table")) ) # COLLECT @@ -898,38 +874,28 @@ test_that("Encounter..interface_methods DuckDB", { ) # COMPUTE - expect_equal( - encounter_object@record$lazy_query$x$x, - structure("inpatient_episodes", class = c("ident", "character")) - ) + expect_is(encounter_object@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(encounter_object@record$lazy_query$x$x, "table"), "inpatient_episodes") encounter_object_computed <- compute(encounter_object) expect_true( grepl("^dbplyr_", - as.character( - encounter_object_computed@record$lazy_query$x - )) - ) - expect_equal( - encounter_object_multi@record$lazy_query$x$x, - structure("inpatient_episodes", class = c("ident", "character")) + vctrs::field(encounter_object_computed@record$lazy_query$x, "table")) ) + + expect_is(encounter_object_multi@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(encounter_object_multi@record$lazy_query$x$x, "table"), "inpatient_episodes") encounter_object_multi_computed <- compute(encounter_object_multi) expect_true( grepl("^dbplyr_", - as.character( - encounter_object_multi_computed@record$lazy_query$x - )) - ) - expect_equal( - encounter_object_multi5@record$lazy_query$x$x, - structure("inpatient_episodes", class = c("ident", "character")) + vctrs::field(encounter_object_multi_computed@record$lazy_query$x, "table")) ) + + expect_is(encounter_object_multi5@record$lazy_query$x$x, "dbplyr_table_ident") + expect_equal(vctrs::field(encounter_object_multi5@record$lazy_query$x$x, "table"), "inpatient_episodes") encounter_object_multi5_computed <- compute(encounter_object_multi5) expect_true( grepl("^dbplyr_", - as.character( - encounter_object_multi5_computed@record$lazy_query$x - )) + vctrs::field(encounter_object_multi5_computed@record$lazy_query$x, "table")) ) # COLLECT