Skip to content

Commit

Permalink
Merge pull request #307 from OHDSI/documentation-helpers
Browse files Browse the repository at this point in the history
updates documentation of dateRange
  • Loading branch information
cecicampanile authored Jan 28, 2025
2 parents 03f1979 + 06701b8 commit ec80c69
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 44 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Imports:
tibble,
tidyr
Depends:
R (>= 4.1.0)
R (>= 4.1)
URL: https://OHDSI.github.io/OmopSketch/
BugReports: https://github.com/OHDSI/OmopSketch/issues
VignetteBuilder: knitr
Expand Down
12 changes: 12 additions & 0 deletions R/documentationHelper.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Argument descriptions repeated > 1:

#' Helper for consistent documentation of `dateRange`.
#'
#' @param dateRange A vector of two dates defining the desired study period.
#' Only the `start_date` column of the OMOP table is checked to ensure it falls within this range.
#' If `dateRange` is `NULL`, no restriction is applied.
#'
#'
#' @name dateRange-startDate
#' @keywords internal
NULL
3 changes: 1 addition & 2 deletions R/summariseClinicalRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#' @param ageGroup A list of age groups to stratify results by.
#' @param sex Boolean variable. Whether to stratify by sex (TRUE) or not
#' (FALSE).
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#' @return A summarised_result object.
#' @export
#' @examples
Expand Down
3 changes: 1 addition & 2 deletions R/summariseConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#' @param sex TRUE or FALSE. If TRUE code use will be summarised by sex.
#' @param ageGroup A list of ageGroup vectors of length two. Code use will be
#' thus summarised by age groups.
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#'
#' @return A summarised_result object with results overall and, if specified, by
#' strata.
Expand Down
3 changes: 1 addition & 2 deletions R/summariseConceptIdCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#' thus summarised by age groups.
#' @param sample An integer to sample the tables to only that number of records.
#' If NULL no sample is done.
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#'
#' @return A summarised_result object with results overall and, if specified, by
#' strata.
Expand Down
3 changes: 1 addition & 2 deletions R/summariseConceptSetCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#' @param sex TRUE or FALSE. If TRUE code use will be summarised by sex.
#' @param ageGroup A list of ageGroup vectors of length two. Code use will be
#' thus summarised by age groups.
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#' @return A summarised_result object with results overall and, if specified, by
#' strata.
#' @export
Expand Down
3 changes: 1 addition & 2 deletions R/summariseInObservation.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#' @param ageGroup A list of age groups to stratify results by.
#' @param sex Boolean variable. Whether to stratify by sex (TRUE) or not
#' (FALSE).
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#' @return A summarised_result object.
#' @export
#' @examples
Expand Down
3 changes: 1 addition & 2 deletions R/summariseMissingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#' thus summarised by age groups.
#' @param sample An integer to sample the table to only that number of records.
#' If NULL no sample is done.
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#'
#' @return A summarised_result object with results overall and, if specified, by
#' strata.
Expand Down
3 changes: 1 addition & 2 deletions R/summariseObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#' @param ageGroup A list of age groups to stratify results by.
#' @param sex Boolean variable. Whether to stratify by sex (TRUE) or not
#' (FALSE).
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#'
#' @return A summarised_result object with the summarised data.
#'
Expand Down
3 changes: 1 addition & 2 deletions R/summariseRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#' @param interval Time interval to stratify by. It can either be "years", "quarters", "months" or "overall".
#' @param ageGroup A list of age groups to stratify results by.
#' @param sex Whether to stratify by sex (TRUE) or not (FALSE).
#' @param dateRange A list containing the minimum and the maximum dates
#' defining the time range within which the analysis is performed.
#' @inheritParams dateRange-startDate
#' @param sample An integer to sample the tables to only that number of records.
#' If NULL no sample is done.
#' @return A summarised_result object.
Expand Down
14 changes: 14 additions & 0 deletions man/dateRange-startDate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseClinicalRecords.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseConceptCounts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseConceptIdCounts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseConceptSetCounts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseInObservation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseMissingData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseObservationPeriod.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/summariseRecordCount.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions tests/testthat/test-summariseConceptSetCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -562,26 +562,26 @@ test_that("dateRange argument works", {
test_that("interval argument works", {
skip_on_cran()
# Load mock database ----
cdm <- mockOmopSketch()
expect_no_error(y<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
cdm <- cdmEunomia()
expect_no_error(y<-summariseConceptSetCounts(list("polio" = c(40213160)),
cdm = cdm,
interval = "years"))

expect_no_error(o<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(o<-summariseConceptSetCounts(list("polio" = c(40213160)),
cdm = cdm,
interval = "overall"))
expect_no_error(q<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(q<-summariseConceptSetCounts(list("polio" = c(40213160)),
cdm = cdm,
interval = "quarters"))
expect_no_error(m<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(m<-summariseConceptSetCounts(list("polio" = c(40213160)),
cdm = cdm,
interval = "months"))



m_quarters <- m|>omopgenerics::splitAdditional()|>
omopgenerics::pivotEstimates() |>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 21603444) |>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 40213160) |>
dplyr::mutate(
start_date = as.Date(sub(" to .*", "", time_interval)),
quarter_start = lubridate::quarter(start_date, type = "date_first"),
Expand All @@ -596,15 +596,15 @@ test_that("interval argument works", {

q_quarters <- q|>omopgenerics::splitAdditional()|>
omopgenerics::pivotEstimates()|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records"& standard_concept_id == 21603444)|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records"& standard_concept_id == 40213160)|>
dplyr::select(time_interval, count)|>
dplyr::arrange(time_interval)

expect_equal(m_quarters, q_quarters)

m_year <- m|>
omopgenerics::splitAdditional()|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 21603444)|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 40213160)|>
dplyr::mutate(
# Extract the start date
start_date = clock::date_parse(stringr::str_extract(time_interval, "^\\d{4}-\\d{2}-\\d{2}")),
Expand All @@ -620,7 +620,7 @@ test_that("interval argument works", {
dplyr::arrange(year)
y_year <- y|>
omopgenerics::splitAdditional()|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 21603444)|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 40213160)|>
dplyr::mutate(
# Extract the start date
start_date = clock::date_parse(stringr::str_extract(time_interval, "^\\d{4}-\\d{2}-\\d{2}")),
Expand All @@ -633,7 +633,7 @@ test_that("interval argument works", {

expect_equal(m_year, y_year)
o <- o |> omopgenerics::splitAdditional()|>
dplyr::filter(variable_name == "Number records" & standard_concept_id == 21603444)|>
dplyr::filter(variable_name == "Number records" & standard_concept_id == 40213160)|>
omopgenerics::pivotEstimates()|>
dplyr::select(count)

Expand All @@ -642,7 +642,7 @@ test_that("interval argument works", {

q_year <- q|>
omopgenerics::splitAdditional()|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 21603444)|>
dplyr::filter(time_interval != "overall" & variable_name == "Number records" & standard_concept_id == 40213160)|>
dplyr::mutate(
# Extract the start date
start_date = clock::date_parse(stringr::str_extract(time_interval, "^\\d{4}-\\d{2}-\\d{2}")),
Expand Down

0 comments on commit ec80c69

Please sign in to comment.