Skip to content

Commit

Permalink
use clock package
Browse files Browse the repository at this point in the history
  • Loading branch information
martaalcalde committed Jul 25, 2024
1 parent a0fd274 commit b3b7d5a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Imports:
stringr,
tibble,
tidyr,
visOmopResults
visOmopResults,
clock
Depends:
R (>= 2.10)
URL: https://oxford-pharmacoepi.github.io/OmopSketch/
Expand Down
4 changes: 2 additions & 2 deletions R/summariseInObservation.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ countRecords <- function(observationPeriod, cdm, start_date_name, end_date_name,
tablePrefix <- omopgenerics::tmpPrefix()

x <- observationPeriod %>%
dplyr::mutate("start" = lubridate::floor_date(.data[[start_date_name]], unit = "month")) |>
dplyr::mutate("end" = lubridate::floor_date(.data[[end_date_name]], unit = "month")) |>
dplyr::mutate("start" = as.Date(paste0(clock::get_year(.data[[start_date_name]]),"/",clock::get_month(.data[[start_date_name]]),"/01"))) |>
dplyr::mutate("end" = as.Date(paste0(clock::get_year(.data[[start_end_name]]),"/",clock::get_month(.data[[start_end_name]]),"/01"))) |>
dplyr::group_by(.data$start, .data$end, .data$sex) |>
dplyr::summarise(n = dplyr::n()) |>
dplyr::compute(
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
on_cran <- function() {
!interactive() && !isTRUE(as.logical(Sys.getenv("NOT_CRAN", "false")))
}

if (!on_cran()) {
withr::local_envvar(
R_USER_CACHE_DIR = tempfile(),
Expand All @@ -9,3 +10,5 @@ if (!on_cran()) {
)
CDMConnector::downloadEunomiaData(overwrite = TRUE)
}


18 changes: 9 additions & 9 deletions tests/testthat/test-summariseInObservation.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ test_that("check sex argument works", {

})
# Load mock database ----
# con <- DBI::dbConnect(duckdb::duckdb(), CDMConnector::eunomia_dir())
# cdm <- CDMConnector::cdmFromCon(
# con = con, cdmSchema = "main", writeSchema = "main"
# )
#
# observationPeriod <- cdm$observation_period
# unit <- "year"
# unitInterval <- 2
# sex <- FALSE
con <- DBI::dbConnect(duckdb::duckdb(), CDMConnector::eunomia_dir())
cdm <- CDMConnector::cdmFromCon(
con = con, cdmSchema = "main", writeSchema = "main"
)

observationPeriod <- cdm$observation_period
unit <- "year"
unitInterval <- 2
sex <- FALSE
12 changes: 6 additions & 6 deletions tests/testthat/test-summariseRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test_that("plotRecordCount() works", {
con = con, cdmSchema = "main", writeSchema = "main"
)
expect_warning(inherits(plotRecordCount(summariseRecordCount(cdm$drug_exposure, unitInterval = 8)),"ggplot"))
# expect_warning(inherits(plotRecordCount(summariseRecordCount(cdm$death, unitInterval = 8)),"ggplot"))
expect_warning(inherits(plotRecordCount(summariseRecordCount(cdm$death, unitInterval = 8)),"ggplot"))
})

test_that("summariseRecordCount() ageGroup argument works", {
Expand Down Expand Up @@ -201,8 +201,8 @@ test_that("summariseRecordCount() sex argument works", {



# omopTable <- cdm$observation_period
# ageGroup <- NULL #list("<=20" = c(0,20), "21 to 40" = c(21,40), "41 to 60" = c(41,60), ">60" = c(61, Inf))
# unit <- "year"
# unitInterval <- 10
# sex <- TRUE
omopTable <- cdm$observation_period
ageGroup <- NULL #list("<=20" = c(0,20), "21 to 40" = c(21,40), "41 to 60" = c(41,60), ">60" = c(61, Inf))
unit <- "month"
unitInterval <- 5
sex <- TRUE

0 comments on commit b3b7d5a

Please sign in to comment.