From 02e3994540539046eeb80e172c1370977c2657de Mon Sep 17 00:00:00 2001 From: Stef Piatek Date: Thu, 29 Aug 2024 09:47:00 +0100 Subject: [PATCH] Add version to returned bundles --- R/bundles.R | 5 +++-- tests/testthat/test-bundles.R | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/bundles.R b/R/bundles.R index 1b2bb61..21025c0 100644 --- a/R/bundles.R +++ b/R/bundles.R @@ -7,7 +7,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 and a domain column for each available concept +#' @return dataframe that contains a "concept_name", "version" and a "domain" column for each available concept #' @export #' @examples #' available_bundles() @@ -17,7 +17,8 @@ available_bundles <- function(version = "latest") { directories <- list.dirs(raw_dir, full.names = TRUE) domain_directories <- directories[directories != raw_dir] - purrr::map_dfr(domain_directories, .build_concepts_from_directory) + purrr::map_dfr(domain_directories, .build_concepts_from_directory) |> + mutate(version = version) } .get_raw_dir <- function(...) { diff --git a/tests/testthat/test-bundles.R b/tests/testthat/test-bundles.R index 5c4ba2e..2df89f9 100644 --- a/tests/testthat/test-bundles.R +++ b/tests/testthat/test-bundles.R @@ -3,9 +3,14 @@ library(omopbundles) library(testthat) -test_that("available_bundles is not empty", { - result <- available_bundles() +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 <- filter(result, concept_name == "antibodies to hiv") + expect_equal(hiv_ab$version, "latest") + expect_equal(hiv_ab$id, "antibodies_to_hiv.csv") + expect_equal(hiv_ab$domain, "measurement") + }) test_that("Smoking exists as an observation", {