Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ablack3 committed Jan 31, 2024
2 parents 2f96e5a + 3a9b2e6 commit 8bad2be
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Imports:
fs,
generics,
tidyr,
omopgenerics
omopgenerics (>= 0.0.2)
Suggests:
SqlRender,
rJava,
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export(cohortAttrition)
export(cohortCount)
export(cohortErafy)
export(cohortSet)
export(cohortTable)
export(cohortUnion)
export(cohort_attrition)
export(cohort_count)
Expand Down Expand Up @@ -76,6 +75,7 @@ export(intersectCohorts)
export(intersect_cohorts)
export(listTables)
export(list_tables)
export(newCohortTable)
export(newGeneratedCohortSet)
export(new_generated_cohort_set)
export(readCohortSet)
Expand Down Expand Up @@ -116,10 +116,10 @@ importFrom(jsonlite,read_json)
importFrom(methods,is)
importFrom(omopgenerics,attrition)
importFrom(omopgenerics,cohortCount)
importFrom(omopgenerics,cohortTable)
importFrom(omopgenerics,dropTable)
importFrom(omopgenerics,insertFromSource)
importFrom(omopgenerics,insertTable)
importFrom(omopgenerics,newCohortTable)
importFrom(omopgenerics,settings)
importFrom(purrr,"%||%")
importFrom(rlang,"!!")
Expand Down
19 changes: 9 additions & 10 deletions R/cdm.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ cdm_from_con <- function(con,
achillesTables <- list()
}

cdm <- omopgenerics::cdmReference(
cdm <- omopgenerics::newCdmReference(
tables = c(cdmTables, achillesTables),
cdmName = cdm_name,
cdmVersion = cdm_version
Expand All @@ -117,16 +117,15 @@ cdm_from_con <- function(con,
NULL
}
})
cohort <- x[[1]]
if(is.null(cohort)) {
cdm[[cohort_table]] <- x[[1]]
if(is.null(cdm[[cohort_table]])) {
rlang::abort(glue::glue("cohort table `{cohort_table}` not found!"))
}

cdm[[cohort_table]] <- omopgenerics::cohortTable(
table = cohort,
cohortSetRef = x[[2]],
cohortAttritionRef = x[[3]]
)
cdm[[cohort_table]] <- cdm[[cohort_table]] |>
omopgenerics::newCohortTable(
cohortSetRef = x[[2]],
cohortAttritionRef = x[[3]]
)
}

if (dbms(con) == "snowflake") {
Expand Down Expand Up @@ -168,7 +167,7 @@ tbl.db_cdm <- function(src, schema, name, ...) {
fullName <- inSchema(schema = schema, table = name, dbms = dbms(con))
x <- dplyr::tbl(src = con, fullName) |>
dplyr::rename_all(tolower) |>
omopgenerics::cdmTable(src = src, name = tolower(name))
omopgenerics::newCdmTable(src = src, name = tolower(name))
return(x)
}

Expand Down
4 changes: 2 additions & 2 deletions R/copy_cdm_to.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ copy_cdm_to <- function(con, cdm, schema, overwrite = FALSE) {
}

# create cdm object
newCdm <- omopgenerics::cdmReference(
newCdm <- omopgenerics::newCdmReference(
tables = cdmTables, cdmName = omopgenerics::cdmName(cdm)
)

Expand Down Expand Up @@ -70,7 +70,7 @@ copy_cdm_to <- function(con, cdm, schema, overwrite = FALSE) {
overwrite = overwrite
)
if (cohort) {
newCdm[[table_name]] <- omopgenerics::cohortTable(
newCdm[[table_name]] <- omopgenerics::newCohortTable(
table = newCdm[[table_name]],
cohortSetRef = newCdm[[paste0(table_name, "_set")]],
cohortAttritionRef = newCdm[[paste0(table_name, "_attrition")]]
Expand Down
6 changes: 3 additions & 3 deletions R/dbSource.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dbSource <- function(con,
"write_schema" = writeSchema
)
class(source) <- "db_cdm"
source <- omopgenerics::cdmSource(src = source, sourceType = dbms(con))
source <- omopgenerics::newCdmSource(src = source, sourceType = dbms(con))
return(source)
}

Expand All @@ -56,7 +56,7 @@ insertTable.db_cdm <- function(cdm,
}
DBI::dbWriteTable(conn = con, name = fullName, value = table)
x <- dplyr::tbl(src = con, fullName) |>
omopgenerics::cdmTable(src = src, name = name)
omopgenerics::newCdmTable(src = src, name = name)
return(x)
}

Expand Down Expand Up @@ -167,7 +167,7 @@ insertFromSource.db_cdm <- function(cdm, value) {
remoteName <- substr(remoteName, nchar(prefix) + 1, nchar(remoteName))
}
}
value <- omopgenerics::cdmTable(
value <- omopgenerics::newCdmTable(
table = value, src = attr(cdm, "cdm_source"), name = remoteName
)
return(value)
Expand Down
8 changes: 4 additions & 4 deletions R/generateCohortSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,11 @@ generateCohortSet <- function(cdm,
# }

cdm[[name]] <- cohort_ref |>
omopgenerics::cdmTable(src = attr(cdm, "cdm_source"), name = name)
omopgenerics::newCdmTable(src = attr(cdm, "cdm_source"), name = name)

# browser()
# Create the object. Let the constructor handle getting the counts.----
cdm[[name]] <- omopgenerics::cohortTable(
cdm[[name]] <- omopgenerics::newCohortTable(
table = cdm[[name]],
cohortSetRef = cohortSet[,c("cohort_definition_id", "cohort_name")],
cohortAttritionRef = cohort_attrition_ref)
Expand Down Expand Up @@ -437,7 +437,7 @@ generate_cohort_set <- function(cdm,
#'
#' `r lifecycle::badge("superseded")`
#'
#' Please use `omopgenerics::cohortTable()` instead.
#' Please use `omopgenerics::newCohortTable()` instead.
#'
#' This constructor function is to be used by analytic package developers to
#' create `cohort_table` objects.
Expand Down Expand Up @@ -563,7 +563,7 @@ new_generated_cohort_set <- function(cohort_ref,
if (!missing(overwrite)) {
cli::cli_warn("overwrite is no longer a required argument for new_generated_cohort_set")
}
omopgenerics::cohortTable(
omopgenerics::newCohortTable(
table = cohort_ref,
cohortSetRef = cohort_set_ref,
cohortAttritionRef = cohort_attrition_ref
Expand Down
2 changes: 1 addition & 1 deletion R/generateConceptCohortSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ generateConceptCohortSet <- function(cdm,
excluded_records = 0,
excluded_subjects = 0)

cdm[[name]] <- omopgenerics::cohortTable(
cdm[[name]] <- omopgenerics::newCohortTable(
table = cohortRef,
cohortSetRef = cohortSetRef,
cohortAttritionRef = cohortAttritionRef
Expand Down
4 changes: 2 additions & 2 deletions R/reexports-omopgenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ omopgenerics::settings
#' @export
omopgenerics::attrition

#' @importFrom omopgenerics cohortTable
#' @importFrom omopgenerics newCohortTable
#' @export
omopgenerics::cohortTable
omopgenerics::newCohortTable

#' @importFrom omopgenerics insertTable
#' @export
Expand Down
2 changes: 1 addition & 1 deletion extras/circe-work.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ DBI::dbRemoveTable(con, inSchema(write_schema, "codesets", dbms(con)))

cdm[[name]] <- cohortRef

cdm[[name]] <- omopgenerics::cohortTable(
cdm[[name]] <- omopgenerics::newCohortTable(
cohortRef = cdm[[name]], cohortSetRef = cohortSetRef, overwrite = overwrite
)

Expand Down
2 changes: 1 addition & 1 deletion man/new_generated_cohort_set.Rd

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

4 changes: 2 additions & 2 deletions man/reexports.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-db-generateCohortSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ test_that("newGeneratedCohortSet works with prefix", {
) %>%
compute(name = "cohort", temporary = FALSE, overwrite = TRUE)

cdm$cohort <- cohortTable(cdm$cohort)
cdm$cohort <- newCohortTable(cdm$cohort)

expect_true("cohort" %in% list_tables(con, write_schema))
expect_true("test_cohort" %in% list_tables(con, "main"))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-db-newGeneratedCohortSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test_new_generated_cohort_set <- function(con, cdm_schema, write_schema) {
cdm$new_cohort <- x %>%
compute(name = "new_cohort", temporary = FALSE, overwrite = TRUE)

cdm$new_cohort <- omopgenerics::cohortTable(
cdm$new_cohort <- omopgenerics::newCohortTable(
cdm$new_cohort,
cohortSetRef = dplyr::tibble(
cohort_definition_id = 1,
Expand Down Expand Up @@ -117,7 +117,7 @@ test_that("error in newGeneratedCohortSet if cohort_ref has not been computed",
"cohort_start_date" = "condition_start_date",
"cohort_end_date" = "condition_end_date")

expect_error(omopgenerics::cohortTable(cohort_ref))
expect_error(omopgenerics::newCohortTable(cohort_ref))

DBI::dbDisconnect(con, shutdown = TRUE)
})
Expand Down Expand Up @@ -163,7 +163,7 @@ test_that("no error if cohort is empty", {

cdm$cohort_3b <- cdm$cohort_3 %>%
dplyr::compute(name = "cohort_3b", temporary = FALSE) |>
omopgenerics::cohortTable(cohortSetRef = c_Ref)
omopgenerics::newCohortTable(cohortSetRef = c_Ref)

expect_true("cohort_table" %in% class(cdm$cohort_3b))
expect_false(nrow(settings(cdm$cohort_3b)) == 0)
Expand Down Expand Up @@ -196,7 +196,7 @@ test_that("newGeneratedCohortSet handles empty cohort tables", {
cdm$cohort_3 <- cdm$cohorts2 %>%
dplyr::filter(cohort_start_date > "2099-01-01") %>%
compute(name = "cohort_3", temporary = FALSE) %>%
omopgenerics::cohortTable()
omopgenerics::newCohortTable()
})

expect_equal(nrow(dplyr::collect(cdm$cohort_3)), 0)
Expand Down
16 changes: 12 additions & 4 deletions tests/testthat/test-validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ test_that("assert_tables works", {
# add missing column error to collection
err3 <- checkmate::makeAssertCollection()
cdm <- cdm_from_con(con, "main", "main")
expect_error({
cdm$person <- cdm$person %>%
dplyr::select(-"person_id")
})

expect_no_error(cdm$person %>%
dplyr::select(-"person_id"))
# but we can't assign it to the cdm
expect_error(cdm$person <- cdm$person %>%
dplyr::select(-"person_id"))

cdm$person <- cdm$person %>%
dplyr::select(-"ethnicity_source_concept_id")
expect_error(assertTables(cdm = cdm, tables = c("person"), add = err3), NA)
expect_length(err3$getMessages(), 1) # missing column
expect_error(assertTables(cdm = cdm, tables = c("person"), add = NULL)) # without error collection

# use in a function (i.e. the typical use case)
countDrugsByGender <- function(cdm) {
Expand Down
6 changes: 3 additions & 3 deletions vignettes/a02_cohorts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ cdm$cohort
To make this a true generated cohort object use the `cohort_table`

```{r}
cdm$cohort <- cohortTable(cdm$cohort)
cdm$cohort <- newCohortTable(cdm$cohort)
```

We can see that this cohort is now has the class "cohort_table" as well as the various metadata tables.
Expand All @@ -324,12 +324,12 @@ If you would like to override the attribute tables then pass additional datafram

```{r}
cdm <- insertTable(cdm = cdm, name = "cohort2", table = cohort, overwrite = TRUE)
cdm$cohort2 <- cohortTable(cdm$cohort2)
cdm$cohort2 <- newCohortTable(cdm$cohort2)
settings(cdm$cohort2)
cohort_set <- data.frame(cohort_definition_id = 1L,
cohort_name = "made_up_cohort")
cdm$cohort2 <- cohortTable(cdm$cohort2, cohortSetRef = cohort_set)
cdm$cohort2 <- newCohortTable(cdm$cohort2, cohortSetRef = cohort_set)
settings(cdm$cohort2)
```
Expand Down
2 changes: 1 addition & 1 deletion vignettes/a06_using_cdm_attributes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ We can add the required attributes using the `newGeneratedCohortSet` function. T
```{r}
GI_bleed_cohort_ref <- tibble(cohort_definition_id = 1, cohort_name = "custom_gi_bleed")
cdm$gi_bleed <- omopgenerics::cohortTable(
cdm$gi_bleed <- omopgenerics::newCohortTable(
table = cdm$gi_bleed, cohortSetRef = GI_bleed_cohort_ref
)
```
Expand Down

0 comments on commit 8bad2be

Please sign in to comment.