Skip to content

Commit

Permalink
Use sensible column name for bundles (#20)
Browse files Browse the repository at this point in the history
* Use bundle_name correctly

* Add styler to project
  • Loading branch information
stefpiatek authored Sep 24, 2024
1 parent c9f786a commit c989601
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Suggests:
pkgload,
lintr,
stringr,
styler,
testthat (>= 3.0.0),
usethis
Config/testthat/edition: 3
Expand Down
4 changes: 2 additions & 2 deletions R/bundles.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @description If a bundle has multiple names, then the id will be duplicated across rows
#'
#' @param version Requested version, if not defined, the latest will be used
#' @return dataframe that contains a "concept_name", "version" and a "domain" column for each available concept
#' @return dataframe that contains a "bundle_name", "version" and a "domain" column for each available bundle
#' @export
#' @examples
#' available_bundles()
Expand All @@ -36,7 +36,7 @@ available_bundles <- function(version = "latest") {
#' @export
#' @examples
#' # Usage with available_bundles, from a single row
#' smoking <- available_bundles() |> dplyr::filter(concept_name == "Smoking")
#' smoking <- available_bundles() |> dplyr::filter(bundle_name == "Smoking")
#' concept_by_bundle(domain = smoking$domain, id = smoking$id, version = smoking$version)
#' # Using if you know the details directly
#' concept_by_bundle(domain = "observation", id = "smoking")
Expand Down
6 changes: 3 additions & 3 deletions R/raw-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' @description If a bundle has multiple names, then the id will be duplicated across rows
#'
#' @return dataframe that contains a "concept_name" and a "domain" column for each available concept
#' @return dataframe that contains a "bundle_name" and a "domain" column for each available bundle
#' @keywords internal
raw_bundles <- function() {
raw_dir <- get_raw_dir()
Expand All @@ -38,12 +38,12 @@ get_raw_dir <- function(..., version = "latest") {


parse_bundle_names <- function(bundle_name_path) {
bundle_name <- bundle_name_path |>
domain_name <- bundle_name_path |>
dirname() |>
basename()

readr::read_csv(bundle_name_path, col_types = "cc") |>
mutate(domain = bundle_name)
mutate(domain = domain_name)
}


Expand Down
2 changes: 1 addition & 1 deletion inst/data-raw/measurement/bundle_names.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,concept_name
id,bundle_name
HBA1c,HBA1c
LDH,LDH
antibodies_to_hiv,Antibodies to HIV
Expand Down
2 changes: 1 addition & 1 deletion inst/data-raw/observation/bundle_names.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id,concept_name
id,bundle_name
smoking,Smoking
2 changes: 1 addition & 1 deletion inst/data-raw/race/bundle_names.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id,concept_name
id,bundle_name
snomed_race,Race
2 changes: 1 addition & 1 deletion inst/data-raw/unknown/bundle_names.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
id,concept_name
id,bundle_name
indices_of_deprivation,Indices of deprivation
2 changes: 1 addition & 1 deletion man/available_bundles.Rd

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

2 changes: 1 addition & 1 deletion man/concept_by_bundle.Rd

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

3 changes: 2 additions & 1 deletion man/raw_bundles.Rd

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

3 changes: 2 additions & 1 deletion man/raw_concept_by_bundle.Rd

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

5 changes: 5 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,11 @@
],
"Hash": "960e2ae9e09656611e0b8214ad543207"
},
"styler": {
"Package": "styler",
"Version": "1.10.3",
"Source": "Repository"
},
"sys": {
"Package": "sys",
"Version": "3.4.2",
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-bundles.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
test_that("available_bundles isn't empty and have correct columns", {
result <- omopbundles::available_bundles()
expect_true(nrow(result) > 0, info = "The dataframe should not be empty")
hiv_ab <- dplyr::filter(result, concept_name == "Antibodies to HIV")
hiv_ab <- dplyr::filter(result, bundle_name == "Antibodies to HIV")
expect_equal(hiv_ab$version, "latest")
expect_equal(hiv_ab$id, "antibodies_to_hiv")
expect_equal(hiv_ab$domain, "measurement")

})

test_that("Smoking exists as an observation", {
result <- available_bundles() |>
dplyr::filter(concept_name == "Smoking")
dplyr::filter(bundle_name == "Smoking")

expect_true(nrow(result) == 1, info = "Smoking should only exist as a single row")
expect_equal(result$domain, "observation")
Expand All @@ -25,7 +24,7 @@ test_that("Concept by bundle works with character values", {

test_that("Available bundles and concept_by_bundle play nicely together", {
smoking_bundle <- available_bundles() |>
dplyr::filter(concept_name == "Smoking")
dplyr::filter(bundle_name == "Smoking")

smoking_concepts <- concept_by_bundle(smoking_bundle$domain, smoking_bundle$id)

Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-raw-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ assert_bundle_has_name <- function(bundle) {
bundle_name_file <- get_raw_dir(bundle$domain, "bundle_names.csv")
bundle_names <- read_csv(bundle_name_file, show_col_types = FALSE)

expect_true(bundle$id %in% bundle_names$id,
glue::glue("{bundle$id} should at least one name in: {bundle$domain}/bundle_names.csv"))
expect_true(
bundle$id %in% bundle_names$id,
glue::glue("{bundle$id} should at least one name in: {bundle$domain}/bundle_names.csv")
)
}

test_that("All raw bundles have at least one name", {
Expand All @@ -38,5 +40,4 @@ test_that("All raw bundle names map to a bundle file that has at least one conce
# Check that at least one concept
expect_true(nrow(concepts) > 0)
})

})

0 comments on commit c989601

Please sign in to comment.