Skip to content

Commit

Permalink
Ensure concept IDs are always returned as integers (#21)
Browse files Browse the repository at this point in the history
* Ensure concept IDs are always returned as integers

* Add test case to check integer type

* Import `rlang::.data`

* Use 4-space indentation in `DESCRIPTION`

* Set the type in the reading step
  • Loading branch information
milanmlft authored Sep 25, 2024
1 parent 652f2a4 commit 0d24c38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
27 changes: 14 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ License: Apache License (>= 2)
Encoding: UTF-8
LazyData: true
Imports:
dplyr (>= 1.0),
glue (>= 1.0),
purrr (>= 1.0),
readr (>= 2.0),
vroom (>= 1.0)
dplyr (>= 1.0),
glue (>= 1.0),
purrr (>= 1.0),
readr (>= 2.0),
rlang (>= 1.1),
vroom (>= 1.0)
Suggests:
devtools,
pak,
pkgload,
lintr,
stringr,
styler,
testthat (>= 3.0.0),
usethis
devtools,
pak,
pkgload,
lintr,
stringr,
styler,
testthat (>= 3.0.0),
usethis
Config/testthat/edition: 3
RoxygenNote: 7.3.2
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ importFrom(dplyr,tibble)
importFrom(glue,glue)
importFrom(purrr,map_dfr)
importFrom(readr,read_csv)
importFrom(rlang,.data)
importFrom(vroom,problems)
6 changes: 5 additions & 1 deletion R/bundles.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ available_bundles <- function(version = "latest") {
#' @param domain The domain of the bundle.
#' @param id The ID of the bundle.
#' @param version The version of the bundle. Default is "latest".
#'
#' @return A data frame with the concept data.
#' @export
#'
#' @importFrom rlang .data
#'
#' @examples
#' # Usage with available_bundles, from a single row
#' smoking <- available_bundles() |> dplyr::filter(bundle_name == "Smoking")
Expand All @@ -42,6 +46,6 @@ available_bundles <- function(version = "latest") {
#' concept_by_bundle(domain = "observation", id = "smoking")
concept_by_bundle <- function(domain, id, version = "latest") {
get_raw_dir(version = version, domain, "bundles", glue::glue("{id}.csv")) |>
readr::read_csv(show_col_types = FALSE) |>
readr::read_csv(col_types = readr::cols(concept_id = readr::col_integer())) |>
dplyr::mutate(domain = domain)
}
1 change: 1 addition & 0 deletions tests/testthat/test-bundles.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test_that("Concept by bundle works with character values", {
expect_true(nrow(smoking_concepts) > 1, info = "Smoking should have multiple concepts")
expect_false(any(is.na(smoking_concepts$concept_id)), info = "Concept ids should not be NA")
expect_true(all(smoking_concepts$domain == "observation"), info = "Domain should be set correctly")
expect_type(smoking_concepts$concept_id, "integer")
})

test_that("Available bundles and concept_by_bundle play nicely together", {
Expand Down

0 comments on commit 0d24c38

Please sign in to comment.