Skip to content

Commit

Permalink
Bug fix (#155)
Browse files Browse the repository at this point in the history
* Update extract_data.R

fix error - due to excluded_data table being a completely empty tibble rather than having empty columns if there is no excluded_data. Caused a problem with back-to-back extract_ function uses

* Update extract_data.R

* more tweaks

Forgot I also needed a column "error" and added test.
  • Loading branch information
ehwenk authored Jan 21, 2025
1 parent e78c8fa commit 4437ca3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions R/extract_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ extract_data <- function(database, table = NA, col, col_value, partial_matches_a
dplyr::distinct()

}

if (ncol(database[["excluded_data"]]) == 0) {
database[["excluded_data"]] <- database[["traits"]][0,]
database[["excluded_data"]] <- database[["excluded_data"]] %>%
dplyr::mutate(error = character()) %>%
dplyr::select(error, everything())
}

}

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-extract_.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ test_that("that you can link two calls of `extract_data` together", {
expect_no_error(extract_data(database = subset_by_dataset_id3, table = "contexts", col = "context_property", col_value = "age"))
expect_no_error(subset_by_dataset_id_and_context <- extract_data(database = subset_by_dataset_id3, table = "contexts", col = "context_property", col_value = "age"))
expect_gt(nrow(subset_by_dataset_id3$contexts), nrow(subset_by_dataset_id_and_context$contexts))
expect_equal(c("error", names(subset_by_dataset_id3$traits)), names(subset_by_dataset_id3$excluded_data))
})

test_that("extracts using generalised extract function behaves as expected - extracting by `life_stage", {
Expand Down

0 comments on commit 4437ca3

Please sign in to comment.